Skip to content

Instantly share code, notes, and snippets.

@dyjjones
Created August 9, 2014 23:03
Show Gist options
  • Save dyjjones/7342bc27db767c961652 to your computer and use it in GitHub Desktop.
Save dyjjones/7342bc27db767c961652 to your computer and use it in GitHub Desktop.
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