
whops... i did check it, but that was a copypaste mistake. buggy:
tm_parallelizable_v1 = \n -> sum . takeWhile (>0) $ map (div n) fives where fives = iterate (*5) 1
should be:
tm_parallelizable_v1 = \n -> sum . takeWhile (>0) $ map (div n) fives where fives = iterate (*5) 5
- marc Am Freitag, 24. August 2007 schrieben Sie:
Hi Marc
First off, thanks for your reply.
tm_parallelizable_v1 = \n -> sum . takeWhile (>0) $ map (div n) fives where fives = iterate (*5) 1 Did you check this one? IMHO I think it's producing the 'wrong' answer.
*Main> tm_parallelizable_v1 100 124 (0.00 secs, 0 bytes)
*Main> tm 100 24 (0.00 secs, 0 bytes)
If comparing the result to the other variants is accepted as a sort of proof. ;-)
But calculating the number of trailing zero's of n! is a matter of counting powers of five in the factorized n!: f.e.:
10! = 1 2 3 2^2 5 2*3 7 2^3 3^2 2*5 --> 5^2 --> picking up enough powers of 2 --> (2*5)^2 = 100
So you will have to correct your 'fives' to f.e.
fives = tail $ iterate (*5) 1
Regards
@@i