Created
September 5, 2019 20:30
-
-
Save maxdeliso/98ab958cb7a4018dfb8382f7f2490354 to your computer and use it in GitHub Desktop.
simple sieve of eratosthenes in haskell
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
divides n d = n /= d && mod n d == 0 | |
eratosthenes n = | |
let | |
filter_k_rec d acc = | |
if d * d < n | |
then filter_k_rec (d + 1) $ filter (\n -> not $ divides n d) acc | |
else acc | |
in filter_k_rec 2 [1..n] | |
main = do | |
putStrLn "enter n: " | |
n <- readLn :: IO Int | |
print $ eratosthenes n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment