Last active
December 10, 2015 15:18
-
-
Save haiiro-shimeji/4453127 to your computer and use it in GitHub Desktop.
エラトステネスのふるい
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
primenumber :: Int -> [Int] | |
primenumber x | |
| 1 > x = error "argument 0 must be >0." | |
| 1 == x = [] | |
primenumber x = sieve [2..x] | |
where | |
s = (sqrt . fromIntegral) x | |
sieve :: [Int] -> [Int] | |
sieve (x:[]) = x : [] | |
sieve all@(x:xs) | |
| s < fromIntegral x = all | |
| otherwise = x : sieve [ x' | x' <- xs, 0 /= mod x' x ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment