Perhaps use the distributed rounding function from the numeric script? For example:
load 'numeric' (+/,]) 1 rounddist a * 172 % +/a=. 42 23 5 20 41 40 172 42 23 5 21 41 40 (+/,]) 1 rounddist a * 172 % +/a=. 50 35 50 8 19 11 172 50 35 49 8 19 11 On Wed, Jun 27, 2018 at 3:47 PM, Skip Cave <s...@caveconsulting.com> wrote: > Devon, > > That 0-1 fraction method is a really nice way to generate lots of sets of 6 > random integers 1-70 that sum to 172. > That got me to thinking -- shouldn't we be able to make all the generated > 6-integer sets sum to 172? > > f01=. 1e5 6?@$0 NB. Generating the fractions > > NB. Now if we instument your verb a bit more: > > itt1=. f01#~c=.172=+/"1 b=.([: <. 0.5 + ] * 172 % +/"1)"1 ] f01 > > $itt1 > > 55085 6 > > NB. Not bad. Over half of the strings sum to 172. > > > NB. What about the other half (invert the c selection vector)? > > 5{.b#~-.c > > 42 23 5 20 41 40 > > 50 35 50 8 19 11 > > 37 34 34 17 22 27 > > 49 10 25 2 34 53 > > 30 14 44 15 32 38 > > > How far off are the rest of these strings ? > > d=.172-+/"1 b#~-.-.c > > 20{.d > > 1 _1 1 _1 _1 _1 1 1 _1 1 1 _1 1 1 1 1 1 1 _1 1 > > _20{.d > > 1 1 _1 _1 1 1 _1 _1 _1 _1 _1 1 _1 2 _2 1 1 _1 _1 1 > > > >./d > > 2 > > <./d > > _2 > > NB. Looks like the rest of the strings are off by as much as +/- 2 > > > So we should be able find the discrepancy in the remaining strings, and > randomly pick one or more of the integers in each of the strings to add or > subtract 1 or 2 to. Then all the strings will sum to 172. > > > I'll leave that exercise to the reader... > > > Skip > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm