Created
September 5, 2011 20:36
-
-
Save tivtag/1195860 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Haskell (slow slow slow first 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 | |
import Data.List | |
primes n = sieve [2..n] 2 | |
sieve [] _ = [] | |
sieve xs n = | |
n : (sieve left (head left)) | |
where marked = [x | x <- xs, x `rem` n == 0] | |
left = xs \\ marked |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment