permC =: (# %&((*/))&:(!@x:) #/.~)
this takes a list as argument, and the innerverb takes the factorials of the
count, and divides with the product of the factorials of item frequencies.
I notice that there is not much difference between these 2 functions:
20 timespacex '*/ 2 + i. <: 500x'
0.000897903 156928
20 timespacex '!500x'
0.000890463 88448
The permutation count of a list is guaranteed to be an integer which means that
every single term on the right hand side is combinable into a term that exists
on the left hand side.
permC 8 # 0 1 2
9465511770
the left and right product lists,
((2 + i.@<:) 24) ; ;@:((2 + i.@<:) each) 8 8 8
so find f such that,
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 f 2 3 4 5 6 7 8 2
3 4 5 6 7 8 2 3 4 5 6 7 8
is faster than permC, likely resulting in no division step.
One quick optimization may be: (removing largest frequency from left hand side)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 f 2 3 4 5 6 7 8 2 3 4 5 6 7 8
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm