If no repeats are permitted, the largest number in the sum would be 79 and the others would be 21 = +/ 1 2 3 4 5 6. Work down from 79. The memo operator M. would come in handy, I expect.
From your description, it is not required to exhibit the sums, just to calculate the number of sums, so you probably don't need to consume a lot of memory in the calculation. On Tue, Apr 16, 2019 at 2:13 PM 'Skip Cave' via Programming < [email protected]> wrote: > I ran across this problem on Quora... How many ways can 100 be written as a > sum of 7 ordered positive integers? (no repeats) > The obvious brute force approach in J would be: > > > odo=: #: i.@(*/) NB. Odometer verb > > #b=.~./:~"1 a#~100=+/"1 a=.odo 7#100 > > |limit error: odo > > | #b=:~./:~"1 a#~100=+/"1 a=: odo 7#100 > > Of course, odo 7#100 generates 1e14 integers (100^7) which exceeds memory. > > So what would the most efficient way to solve this question in J? The most > concise? > > > Skip > > Skip Cave > Cave Consulting LLC > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
