Henry,
Nice! I was trying to solve a Quora problem that asks:
What is total number of positive integer solutions for (x, y, z) such that
xyz=24?
<https://www.quora.com/What-is-total-number-of-positive-integral-solutions-for-x-y-z-such-that-xyz-24>
I wanted to generalize the problem.
So first we need to factor the number:
q:24
2 2 2 3 - these are the factors of 24. I'll add 1 to the list to include it
as a factor. The instructions didn't specify this, but most of the answers
on Quora included 1 as a factor.
We need to build a function that will find all the ways to partition the
factors into three groups:
First build a combination function:
com=: ((= +/"1) |.@:I.@# ]) #:@i.@(2&^)
and a partition function, thanks to Henry:
par =: 2 (}. i.)&.>/\"1 0: ,. (com&.<:) ,. ]
So now design a function that will find all the positive integer solutions
for any integer w, such that x*y*z = w
*/"1(>3 par #a){a=.1,q:24
1 2 12
1 4 6
1 8 3
2 2 6
2 4 3
4 2 3
*/"1(>3 par #a){a=.1,q:50
1 2 25
1 10 5
2 5 5
*/"1(>3 par #a){a=.1,q:32
1 2 16
1 4 8
1 8 4
1 16 2
2 2 8
2 4 4
2 8 2
4 2 4
4 4 2
8 2 2
*/"1(>3 par #a){a=.1,q:13
(blank) There aren’t any solutions for 13
Skip
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm