Last year (24 aug) I started a thread about counting the number of
trailing zero's of a factorial. Modifying some of these verbs will give you:
fF=:[:+/[:<.]%[^>:@i.@<[EMAIL PROTECTED] NB. modified version of R Miller
or
mF=: +/@}.@(<[EMAIL PROTECTED]:a:)
2 mF 10
8
2 3 5 fF"0 [ 100000
99994 49995 24999
2 3 5 mF 100000
99994 49995 24999
Exponents of all prime factors of !20:
(i.&.(_1&p:) mF ]) 20
18 8 4 2 1 1 1 1
__ q: !20
2 3 5 7 11 13 17 19
18 8 4 2 1 1 1 1
=@@i
Geoff Canyon schreef:
I've created a function to figure out how many times a large factorial
will have a given number as a factor.
So for example, !10 has 2 as a factor 8 times:
2 1
4 2
6 1
8 3
10 1
Here's the function I defined to calculate this:
f=: 2&{@:((0&{ , (0 , 2&{) + [: <. 1&{ % 0&{)^:_)
It takes three arguments: the factor, the factorial, and the starting
number for the factor-count, which should always be 0.
It divides the factorial number by the factor repeatedly, keeping
track of the sum of the quotients, and at the end outputs just the sum.
Is this a reasonable job of J programming? Is there a better way to
have coded this?
regards,
Geoff
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm