Created
September 6, 2011 16:10
-
-
Save tivtag/1198004 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Haskell (much faster second try)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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