
24 Aug
2007
24 Aug
'07
3:18 a.m.
Hi, I defined several functions for calculating the number of trailing zero's of n! tm = sum . takeWhile(>0) . iterate f . f where f = flip div 5 tm1 n = sum . takeWhile(>0) . map (div n . (5^)) $ [1..] tm2 n = sum . takeWhile(>0) . map (div n) $ iterate ((*)5) 5 tm3 = sum . takeWhile(>0) . flip map (iterate ((*)5) 5) . div Questions: Which one is the most elegant one generally speaking? Which one is most natural in Haskell? Is there more 'beauty' to possible? My personal choice is 'tm'. I like 'tm3' (a revised version of tm2) in terms of pointlessness and not having a 'where', but I think it's a bit contrived because of the 'flip'. Comments? Thanks @@i