Skip to content

Instantly share code, notes, and snippets.

@tivtag
Created September 5, 2011 20:36
Show Gist options
  • Save tivtag/1195860 to your computer and use it in GitHub Desktop.
Save tivtag/1195860 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes in Haskell (slow slow slow first try)
-- 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