I need a fast algorithm to find all factorizations of a number. This
method is terribly redundant, let's say the prime factors are 2^19 .
And the method is get the nub of the product of all complete partitions
of all the permutations of the prime factors.
boxdraw_j_ 1
permutations=: A.&i.~ !
unique_permutations=: ~.@:({~ permutations@:#)
unique_permutations 'aab'
aab
aba
baa
unique_permutations q:24
2 2 2 3
2 2 3 2
2 3 2 2
3 2 2 2
complete_partitions=: <;.1"_ 1~ (1 ,. [: #: [: i. 2 ^ [: <: [: # {.)
complete_partitions ,:'abc'
+---+--+-+
|abc| | |
+---+--+-+
|ab |c | |
+---+--+-+
|a |bc| |
+---+--+-+
|a |b |c|
+---+--+-+
([: < [: /:~ -.&1)"1 */&> complete_partitions unique_permutations q:24
+--+----+---+-----+----+-----+-----+-------+
|24|3 8 |4 6|2 3 4|2 12|2 3 4|2 2 6|2 2 2 3|
+--+----+---+-----+----+-----+-----+-------+
|24|2 12|4 6|2 3 4|2 12|2 2 6|2 2 6|2 2 2 3|
+--+----+---+-----+----+-----+-----+-------+
|24|2 12|4 6|2 2 6|2 12|2 2 6|2 3 4|2 2 2 3|
+--+----+---+-----+----+-----+-----+-------+
|24|2 12|4 6|2 2 6|3 8 |2 3 4|2 3 4|2 2 2 3|
+--+----+---+-----+----+-----+-----+-------+
NB. multiplication commutes, allowing simplification
,. ([: ~. [: , ([: < [: /:~ -.&1)"1) */&> complete_partitions
unique_permutations q:24
+-------+
|24 |
+-------+
|3 8 |
+-------+
|4 6 |
+-------+
|2 3 4 |
+-------+
|2 12 |
+-------+
|2 2 6 |
+-------+
|2 2 2 3|
+-------+
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm