[Haskell-cafe] Prime finding

Ruben Zilibowitz r.zilibowitz at student.unsw.edu.au
Thu Feb 22 12:02:36 EST 2007

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:

It seems to perform reasonably well. It also has the advantage of  
being quite short.


More information about the Haskell-Cafe mailing list