For those interested in the Sieve of Eratosthenes, have a look at:
http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf
The examples in the paper are in Haskell, but I have been
corresponding with the author who provided this Python version:
def sieve():
innersieve = sieve()
prevsquare = 1
On Jan 16, 12:42 pm, Mark Hahnenberg wrote:
> When I execute this code, the numbers 2,3,4,...,11 are printed (i.e.
> nothing gets filtered out). Could anyone explain why this is
> happening? I generally understand generators, and my hypothesis is
> that reassigning to nats the result of filterin
I'm trying to make a lazy, (theoretically) infinite prime number sieve
using generators. The code I have thus far is:
#!/usr/bin/env python
import itertools
def sieve():
nats = naturals(2)
while True:
elem = nats.next()
yield elem
nats = itertools.ifilterfalse(lambda x: