[Haskell-cafe] New simplified primes; no VIP necessary.
Will Ness
will_n48 at yahoo.com
Thu Dec 23 09:08:00 CET 2010
Hi,
For those who remember the discussion about this about a year ago, it turns out
there was a simpler version after all lurking somewhere in there (or is it
_out_?).
I've just posted it to the haskellwiki's Prime Numbers page:
primes = 2: primes'
where
primes' = 3: 5: [7,9..] `minus` tfold
[ [p*p,p*p+2*p..] | p <- primes' ]
tfold ((x:xs):t) = x : xs `union` tfold (pairs t)
pairs ((x:xs):ys:t) = (x: union xs ys) : pairs t
The full code with double-feed, wheel and better folding structure is also
there. Speed and complexity weren't changed by this. But it is rather
_short_. :)
Cheers,
More information about the Haskell-Cafe
mailing list