
22 Feb
2007
22 Feb
'07
12:02 p.m.
I see that there has been some discussion on the list about prime finding algorithms recently. I just wanted to contribute my own humble algorithm: primes :: [Integer] primes = primesFilter 1 [2..] primesFilter :: Integer -> [Integer] -> [Integer] primesFilter primorial (n:ns) | (gcd primorial n == 1) = n : (primesFilter (primorial*n) ns) | otherwise = primesFilter primorial ns Comparing it to some of the algorithms in: http://www.haskell.org/pipermail/haskell-cafe/2007-February/022765.html It seems to perform reasonably well. It also has the advantage of being quite short. Ruben