[Haskell-cafe] Re: Simple FAST lazy functional primes

Will Ness will_n48 at yahoo.com
Mon Nov 2 11:11:53 EST 2009


Sjoerd Visscher <sjoerd <at> w3future.com> writes:

> 
> Excuse me, 2 doesn't have to be in the list of smaller primes, as  
> we're only generating odd numbers:
> 
> primes = 2 : 3 : 5 : 7 : sieve [3] (drop 2 primes)
> sieve qs@(q:_) (p:ps)
>         = [x | x<-[q*q+2,q*q+4..p*p-2], and [(x`rem`p)/=0 | p<-qs]]
>           ++ sieve (p:qs) ps
> 
> Sjoerd
> 

Hi,

I've run it now. In producing 100,000 primes, your above code takes x3.5 more
time than the one I posted. The code modified as I suggested with (qs++[p])
takes exactly the same time as mine. :)

Cheers,




More information about the Haskell-Cafe mailing list