Last active
August 29, 2015 14:03
-
-
Save m1el/d75089bbd1a3e61e2ba8 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
import System.Environment | |
isPrime :: Int -> Bool | |
isPrime a = | |
let isOddBy x = a `mod` x /= 0 | |
gtSqr x = x * x <= a | |
in all isOddBy $ takeWhile gtSqr primes | |
primes :: [Int] | |
primes = 2 : filter isPrime [3..] | |
main = do | |
args <- getArgs | |
if length args == 0 then | |
print "not enough arguments" | |
else | |
let count = read $ head args | |
in print $ show $ take count primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment