Created
August 9, 2014 23:04
-
-
Save dyjjones/6f9e3219e603e8958644 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
function is_prime(n) | |
if n < 4 | |
return true | |
end | |
if n % 2 == 0 | |
return false | |
end | |
for a = 3:int(sqrt(n)) | |
if n % a == 0 | |
return false | |
end | |
end | |
return true | |
end | |
function calculate_primes(n) | |
primes = Int64[] | |
p = 1 | |
for i = 1:n | |
while ! is_prime(p) | |
p += 1 | |
end | |
push!(primes, p) | |
p += 1 | |
end | |
return primes | |
end | |
calculate_primes(int(ARGS[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment