Skip to content

Instantly share code, notes, and snippets.

@anfedorov
Created February 19, 2010 16:07
Show Gist options
  • Save anfedorov/308835 to your computer and use it in GitHub Desktop.
Save anfedorov/308835 to your computer and use it in GitHub Desktop.
from itertools import islice
def after(n=0):
while 1:
n += 1
yield n
def filter_factors(n, g):
while 1:
x = g.next()
if x % n:
yield x
def primes():
g = after(1)
while 1:
x = g.next()
g = filter_factors(x, g)
yield x
print list(islice(primes(), 0, 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment