My solution is based on the following recurrence formula of the generating
function: h(m,n) = h(m,n-m) + h(m-1, n-m).
Memoizing, as Roger pointed, helps a lot. The agenda is used to handle the edge
cases such as negative n or h(0,0) = 1.
h=:1:`0:`0:`(([h-~)+(<:@[h-~))`0: @.(#.@(,&*)) M.
7 h
I’ve worked up a number of variant explicit partition functions. One of these
is mpart;
m mpart n yields all m-partitions of n, with no zeros, but allowing repeats.
So, for example, using a smallish example:
3 mpart 7. NB. there are four 3-partitions of 7
3 2 2
3 3 1
4 2 1
5 1 1
This
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 p
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=: o
?~@10^:(>:@i.) 4
6 3 9 1 0 4 5 8 7 2
2 4 7 8 3 0 1 5 9 6
6 9 5 7 1 4 8 2 0 3
9 8 6 4 5 2 7 0 3 1
On Tue, Apr 16, 2019 at 8:55 AM David Lambert wrote:
>
> ([: }. ([: ?~ 10"_)^:(<1 2 p. 2)) ''
> 3 8 5 0 9 7 2 1 4 6
> 1 5 6 9 7 2 0 4 3 8
> 1 5 8 2 4 0 3 9 7 6
> 4 0 6 7 1 8 3 9 2 5
>
>
>
Doh! I kept thinking about the power primitive, when I should have
realized that extending the right argument of ? would do the trick. Thanks
to JmageK and Rob for pointing out various straightforward ways to do that.
Skip
On Tue, Apr 16, 2019 at 4:31 AM Skip Cave wrote:
> How can I use the p
Let’s pretend that 10?10 was a placeholder rather than your desired
operation. Let’s also pretend that your desired operation doesn’t support
something like 10 10 10 10?10
Typically we would want to use rank (") to solve this problem, but let’s
pretend we have carefully thought about this, and th
([: }. ([: ?~ 10"_)^:(<1 2 p. 2)) ''
3 8 5 0 9 7 2 1 4 6
1 5 6 9 7 2 0 4 3 8
1 5 8 2 4 0 3 9 7 6
4 0 6 7 1 8 3 9 2 5
please note that I still haven't fixed my four and five keys.
Date: Tue, 16 Apr 2019 04:31:06 -0500
From: "'Skip Cave' via Programming"
To:"programm...@jsoftware.com"
Subje
(10$10)?10
0 1 8 2 6 7 9 4 5 3
8 7 6 9 5 2 0 4 1 3
9 5 0 6 8 1 7 3 2 4
3 9 1 8 5 4 2 6 0 7
0 8 9 2 3 6 7 5 4 1
9 4 6 2 0 5 3 8 1 7
1 9 5 8 2 4 0 7 6 3
5 7 9 6 2 8 3 0 4 1
9 0 6 1 7 8 3 5 2 4
7 4 0 1 2 3 9 8 6 5
Den tirsdag den 16. april 2019 11.50.57 CEST skrev 'Rob Hodgkins
Or for the case of ? you can just do:
10?10 10 10 10 NB. This is just 4 calls of 10?10 (scalar extension
on left argument)
9 8 2 1 4 3 6 0 7 5
9 5 0 4 8 7 6 2 3 1
5 9 7 1 8 3 4 0 6 2
4 2 1 9 8 7 3 6 0 5
Power ^: is useful when successive iterations are required (eg Fibonacci,
Newton
I would do (?~) 4 $ 10
JmageK
--
Securely sent with Tutanota
Apr 16, 2019, 3:01 PM by programm...@jsoftware.com:
> How can I use the power primitive ^: to execute 10?10 four times?
> I want something like this:
>
> (10?10)^: 4
>
> 8 0 9 6 5 7 4 3 1 2
>
> 5 3 1 8 0 9 7 6 2 4
>
> 1 4 6 0 2 5 8 9
How can I use the power primitive ^: to execute 10?10 four times?
I want something like this:
(10?10)^: 4
8 0 9 6 5 7 4 3 1 2
5 3 1 8 0 9 7 6 2 4
1 4 6 0 2 5 8 9 3 7
1 9 7 2 0 8 3 4 5 6
Skip
--
For information about J forum
12 matches
Mail list logo