Skip to content

Instantly share code, notes, and snippets.

@akiross
Created July 6, 2017 12:06
Show Gist options
  • Save akiross/3dbab3d77853e77edb1f2e1fccbd1497 to your computer and use it in GitHub Desktop.
Save akiross/3dbab3d77853e77edb1f2e1fccbd1497 to your computer and use it in GitHub Desktop.
Generating prime numbers in chunks
def extend(old, new):
for p in old:
cand = []
for n in new:
if n % p != 0:
cand.append(n)
if not cand:
return old
old.append(cand[0])
new = cand[1:]
extend([2], range(3, 10)) # [2, 3, 5, 7]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment