If you are looking for a way of verifying Henry's and Roger's approaches, perhaps this:
A partition of three integers summing to X can be broken down into an integer Y and a partition of two integers Z. We want X=Y+Z and we want both integers in Z to not exceed Y. If we ignore the Y constraint, the number of partitions of two integers summing to Z is <.Z%2 If we include the Y constraint, the number of partitions of two integers summing to Z is 0 >. (<.Z%2) <. <.(Z -~ 2 2 p. Y)%2 (please double check my work here, I don't feel up to explaining this right now) The relevant values of Y vary from 1 through X-2 (anything outside this range contributes zero to the sum of possibilities). And, Z=X-Y So, anyways, we can define ZY to determine how many partitions sum to Z with the constraint that both of them are smaller than Y: ZY=: 0 >. <.@-:@[ <. <.@-:@(-~ 2 2&p.) And, we can define X as the sum of all relevant possibilities here: X=: +/@(- ZY ]) 1 + i.@-&2 X 1e6 83333333333 That looks pretty close (assuming I haven't made any mistakes)... -- Raul On Sun, May 20, 2018 at 1:42 PM, Skip Cave <s...@caveconsulting.com> wrote: > I can follow Henry's clever solution. > > 0 ": 6 %~ (-: 999998 * 999999) + 3 * -: 999998 > > 83333333333 > > I tried to replicate Roger's partition approach, and ran into memory > issues. Roger must have more memory on his machine: > > pnk > > 4 : 0"0 > > n=. 0>.x [ k=. y > > if. 1>:n<.k do. x: (0<n)*1=k else. ((n-1) pnk k-1) + (n-k) pnk k end. > > ) > > 1e2 pnk 3 > > 833 > > 1e3 pnk 3 > > 83333 > > 1e4 pnk 3 > > |stack error: pnk > > | ((n-1)pnk k-1)+(n-k) pnk k > > However, as Roger points out, this still does show the trend that the > answer is likely 83333333333. > > Then I tried to replicate Roger's second approach: > > +/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e2 > > _2207 > > +/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e3 > > _247007 > > +/ <.@(%&2)@<: n - 3*i.<.n-3 [ n=: 1e4 > > _24970007 > > > Engine: j807 /j64/windows Beta-c: commercial/2018-03-13T17:40:01 Library: > 8.07.09 Qt IDE: 1.7.1/5.9.4 Platform: Win 64 > > > Something's wrong here, as I can't replicate Roger's results, but I'm not > sure what is going wrong. > > > Skip > > > > > On Sun, May 20, 2018 at 9:31 AM Henry Rich <henryhr...@gmail.com> wrote: > >> Taking advantage of the fact that thepartitions have only 3 elements. >> >> If the first number is i, the second number can be anything from 1 to >> 999999-iand the third number is then uniquely fixed. >> >> Since ican run from 1 to 999998, the total number of such choices is (-: >> 999998 * 999999). >> >> But this counts triplets more than once. Any triplet in which the >> numbers are unique will be counted 6 times. >> >> Any triplet containing a repetition will be counted 3 times: once when i >> is the unrepeated number and twice when i is the repeated number. This >> happens here whenever i is even, thus >> (-:999998) times. >> >> Any triplet containing all 3 numbers equal will be counted just once, >> but there aren't any of them. >> >> To find the unique triplets, we take (-: 999998 * 999999), add in 3 * >> (-:999998) to bring the 3-times-repeated cases up to 6-times-repeated, >> then divide by 6: >> >> 0 ": 6 %~ (-: 999998 * 999999) + 3 * -: 999998 >> >> 83333333333 >> >> >> Henry Rich >> >> >> >> --- >> This email has been checked for viruses by AVG. >> http://www.avg.com >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm