
26 Aug
2007
26 Aug
'07
7:13 a.m.
Bjorn Bringert wrote:
Here's a much more inefficient version, but it has the merit of being very easy to understand:
tm_silly n = length $ takeWhile (=='0') $ reverse $ show $ product [1..n]
Be careful with types - use Data.List.genericLength here instead of length. Otherwise, tm_silly n is wrong for n >= 13 (on my 32-bit machine) due to round-off error in the Int type. Here is another implementation:
base5 n | n < 1 = [] | otherwise = let (q, r) = n `divMod` 5 in r : base5 q
tm6 = sum . zipWith (*) [(5^k-1)`div`4 | k <- [0..]] . base5
Regards, Yitz