Skip to content

Instantly share code, notes, and snippets.

@anfedorov
Created February 19, 2010 19:39
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 anfedorov/309109 to your computer and use it in GitHub Desktop.
Save anfedorov/309109 to your computer and use it in GitHub Desktop.
from itertools import islice
from time import time
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
start = time()
print list(islice(primes(), 0, 498))
print time() - start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment