Skip to content

Instantly share code, notes, and snippets.

@tivtag
Created September 6, 2011 16:10
Show Gist options
  • Save tivtag/1198004 to your computer and use it in GitHub Desktop.
Save tivtag/1198004 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Haskell (much faster second try)
-- Sieve of Eratosthenes
sieve :: [Int] -> [Int]
sieve [] = []
sieve (p:xs) = p : sieve [x|x <- xs, x `mod` p /= 0]
primes :: Int -> [Int]
primes n = sieve [2..n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment