Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def allnumbers(i=1):
- while True:
- yield i
- i += 1
- def fastforward(it, till, it_head=None):
- n = next(it) if it_head is None else it_head
- while n < till:
- n = next(it)
- return n
- def multiples(n):
- for m in allnumbers():
- yield n * m
- def exclude(xs, ys):
- y = None
- for x in xs:
- y = fastforward(ys, x, it_head=y)
- if x is not y:
- yield x
- def sieve(s=allnumbers(i=2)):
- while True:
- s1 = next(s)
- yield s1
- s = exclude(s, multiples(s1)
Add Comment
Please, Sign In to add comment