[Haskell-cafe] Style

Arie Groeneveld bradypus at xs4all.nl
Fri Aug 24 04:08: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]
> >
>   
You're rigth. I came up with that one too the first time. But for large
value's of n
it takes too much time. You may improve that (time) by using another
product
formula:

*Main> length $ takeWhile (=='0') $ reverse $ show $ foldl' (*) 1 [1..30000]
7498
(0.96 secs, 790685000 bytes)

*Main> length $ takeWhile (=='0') $ reverse $ show $ product [1..30000]
7498
(4.05 secs, 792259140 bytes)

But:

*Main> tm 30000
7498
(0.00 secs, 524924 bytes)


Thanks

@@i







More information about the Haskell-Cafe mailing list