Skip to content

Instantly share code, notes, and snippets.

@dbalan
Created March 13, 2016 12:28
Show Gist options
  • Select an option

  • Save dbalan/a5cfd8aabe0b11f82df2 to your computer and use it in GitHub Desktop.

Select an option

Save dbalan/a5cfd8aabe0b11f82df2 to your computer and use it in GitHub Desktop.
sieve of erasotenese in haskell
import Control.Monad
series :: [Int]
series = [2..]
filterMulti :: Int -> [Int] -> [Int]
filterMulti n = filter (\x -> x `mod` n /= 0)
sieve :: [Int] -> [Int]
sieve s = p:sieve ps
where
p = head s
ps = filterMulti p $ tail s
main :: IO ()
main = do
n <- liftM read getLine
print $ take n $ sieve series
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment