[Haskell-cafe] Style

Yitzchak Gale gale at sefer.org
Sun Aug 26 07:13:49 EDT 2007


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


More information about the Haskell-Cafe mailing list