Skip to content

Instantly share code, notes, and snippets.

@RSully
Created February 12, 2012 00:13
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 RSully/1805262 to your computer and use it in GitHub Desktop.
Save RSully/1805262 to your computer and use it in GitHub Desktop.
Prime generator - draft concept of 6n±1
prev = []
start = 5
num = start
lastPrime = (0,0)
ctr = 2 # 5 is the 3rd prime
while ctr < 50000:
isPrime = not any(num % n == 0 for n in prev)
if isPrime:
ctr += 1
lastPrime = (ctr, num)
prev.append(num)
if (num+1) % 6 == 0:
num += 2
else:
num += 4
print "%d\t%d" % lastPrime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment