Created
September 21, 2011 14:12
-
-
Save GrAndSE/1232131 to your computer and use it in GitHub Desktop.
Prime numbers searching using Haskell
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
getDivisors num | |
| num < 1 = [] | |
| otherwise = [x | x <- [n | n <- primeNumbers (num - 1), n <= ((floor.sqrt.fromIntegral) (num + 1))], num `mod` x == 0 ] | |
primeNumbers :: Integer -> [Integer] | |
primeNumbers 2 = [2] | |
primeNumbers num = | |
if getDivisors num == [] | |
then primeNumbers (num - 1) ++ [num] | |
else primeNumbers (num - 1) | |
main :: IO() | |
main = print (primeNumbers 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would probably be more efficient to use
instead of