Guest User

Untitled

a guest
Mar 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. def allnumbers(i=1):
  2. while True:
  3. yield i
  4. i += 1
  5.  
  6. def fastforward(it, till, it_head=None):
  7. n = next(it) if it_head is None else it_head
  8. while n < till:
  9. n = next(it)
  10. return n
  11.  
  12. def multiples(n):
  13. for m in allnumbers():
  14. yield n * m
  15.  
  16. def exclude(xs, ys):
  17. y = None
  18. for x in xs:
  19. y = fastforward(ys, x, it_head=y)
  20. if x is not y:
  21. yield x
  22.  
  23. def sieve(s=allnumbers(i=2)):
  24. while True:
  25. s1 = next(s)
  26. yield s1
  27. s = exclude(s, multiples(s1)
Add Comment
Please, Sign In to add comment