Last active
January 3, 2016 05:58
-
-
Save oropon/8419087 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Main where | |
main = putStrLn $ unlines $ map (show) $ primes 1000000 | |
primes :: Int -> [Int] | |
primes max | |
| max < 2 = error "No primes" | |
| otherwise = erat [] [2..max] | |
where | |
erat :: [Int] -> [Int] -> [Int] | |
erat ps [] = ps | |
erat ps (x:xs) | |
| x ^ 2 < max | |
= erat (x:ps) (filter (\n -> n `mod` x /= 0) xs) | |
| otherwise = reverse ps ++ xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment