One problem w/adding the random discrepancy back into a set is that you will go out of the 1-72 band - then you have to handle that piddling difference. At some point, it's faster to grab the low-hanging fruit and be on your way. Whether or not any of this matters depends mainly on the exact problem domain.
On Wed, Jun 27, 2018 at 8:50 PM, Skip Cave <s...@caveconsulting.com> wrote: > All, > > Wow! Chris Burke's suggestion about rounddist works better than what I > expected. > > g=.1 rounddist "1 (* 172 % +/"1)"1 ] f01 > +/172=+/"1 g > > 100000 NB. Now ALL the 6-digit vectors generated sum to 172!! > > > NB. To check: > > >./,g > > 145 > > <./,g > > 0 > > > NB. However, some of the vectors contain integers > 70, and/or some include > a zero, which is out-of-spec: > > NB. Find & count 6 integer vectors in g that have integers > 70 in them > > > #g#~+./"1]100000 6 $70<,g > > 5006 > > NB. So there are still about 5% of the 6 integer vectors that miss the > original spec of integers 1-70 > > #g#~+./"1]100000 6 $0=,g > > 4250 > > And another 4.2% that contain zeros > > > Skip > > > Skip Cave > > Cave Consulting LLC > > > On Wed, Jun 27, 2018 at 6:09 PM chris burke <cbu...@jsoftware.com> wrote: > > > 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 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Devon McCormick, CFA Quantitative Consultant ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm