Skip to content

Instantly share code, notes, and snippets.

@dnene
Created July 5, 2011 10:54
Show Gist options
  • Save dnene/1064649 to your computer and use it in GitHub Desktop.
Save dnene/1064649 to your computer and use it in GitHub Desktop.
Sieve of Erathosnes Generator
def prime_generator():
current = 2
primes = []
while True:
while any(map(lambda x: current % x == 0, primes)):
current += 1
yield current
primes.append(current)
primes2 = prime_generator()
known_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]
for n in known_primes:
assert primes2.next() == n, n
print "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment