Skip to content

Instantly share code, notes, and snippets.

@m1el
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m1el/d75089bbd1a3e61e2ba8 to your computer and use it in GitHub Desktop.
Save m1el/d75089bbd1a3e61e2ba8 to your computer and use it in GitHub Desktop.
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