Created
August 9, 2014 23:03
-
-
Save dyjjones/7342bc27db767c961652 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 sys | |
import math | |
def is_prime(n): | |
if n < 4: | |
return True | |
if n % 2 == 0: | |
return False | |
for a in range(3, int(math.sqrt(n))+1): | |
if n % a == 0: | |
return False | |
return True | |
def calculate_primes(n): | |
"returns an array with n primes" | |
primes = [] | |
p = 1 | |
for i in range(0, n): | |
while not is_prime(p): | |
p += 1 | |
primes.append(p) | |
p += 1 | |
return primes | |
calculate_primes(int(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment