Clojurians
# test-check

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

cddr 23:49:37

How might you go about writing a generator of sequences of numbers which add up to n?

gfredericks 23:51:25

@cddr depends what kind of distribution you want

gfredericks 23:51:59

the easy dumb way to do it is to generate a sequence of numbers and then append (- n sum) to them

gfredericks 23:52:38

also depends on what kind of numbers you mean

cddr 23:54:09

This is related to my question over in #clojure-spec about a having relations between a top-level amount, and children that should add up to that amount

https://clojurians.slack.com/archives/C1B1BB2Q3/p1501686285791508

gfredericks 23:54:54

would it be weird to not generate the top-level amount?

gfredericks 23:55:09

generate just the children, then set the top-level to the sum?

cddr 23:58:38

Yeah that was my first thought too. But then I thought I needed to solve this type of problem anyway but looking back at my code I can't remember why now :slightly_smiling_face:

cddr 23:59:35

In the actual example there are a few more relationships between the top-level and the children