Skip to content

Instantly share code, notes, and snippets.

@Ayrx
Created June 25, 2013 12:46
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 Ayrx/5858181 to your computer and use it in GitHub Desktop.
Save Ayrx/5858181 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes
def gen_prime_sieve(n):
# Implementation uses the Sieve of Eratosthenes
# Optimized code from: http://stackoverflow.com/a/3941967/1170681
a = [True] * n
a[0] = a[1] = False
for (i, isprime) in enumerate(a):
if isprime:
yield i
for n in xrange(i*i, n, i):
a[n] = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment