Skip, in your actual Quora Problem, why not include other triads,
such as 1 1 24, 2 3 4 etc; or, otherwise, why include both 2 4 3 and
4 2 3 ?
Anyway, this is (quite) short and brutish but not too nasty to solve your
Quora problem for quite small numbers and numbers of factors:
|: 24 ([ ( (= */"1)#]) [:>:[#.inv i.@^ ) 3 NB. transpose gratuitous!
1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 4 4 4 4 6 6 6 8 8 12 12 24
1 2 3 4 6 8 12 24 1 2 3 4 6 12 1 2 4 8 1 2 3 6 1 2 4 1 3 1 2 1
24 12 8 6 4 3 2 1 12 6 4 3 2 1 8 4 2 1 6 3 2 1 4 2 1 3 1 2 1 1
It builds triads 1 1 1 , 1 1 2 ,...1 1 24, ... up to 24 24 24, and keeps
just those whose product is 24.
No points for space or time, filtering 30 out of 13824 candidates, but it's
quite straightforward, and it does yield all 30 permutations, which some
of the Quora corresondents appear to consider the requirement.
NB - it's not clear to me what the problem actually is - is 30 the required
answer (number of permutations of 3 suitable factors), or 6 (number of
combinations of same)?
Mike
On 19/10/2017 16:12, 'Skip Cave' via Programming wrote:
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
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm