Last active
September 25, 2020 09:19
-
-
Save brainix/8d1cfc1106f1db828a7bdcbdb3a23c78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def naturals(start): | |
... yield start | |
... yield from naturals(start+1) | |
... | |
>>> def sieve(prev_sieve): | |
... prime = next(prev_sieve) | |
... yield prime | |
... yield from (num for num in prev_sieve if num % prime != 0) | |
... | |
>>> s = sieve(naturals(2)) | |
>>> next(s) | |
2 | |
>>> next(s) | |
3 | |
>>> next(s) | |
5 | |
>>> next(s) | |
7 | |
>>> next(s) | |
9 | |
>>> next(s) | |
11 | |
>>> next(s) | |
13 | |
>>> next(s) | |
15 | |
>>> next(s) | |
17 | |
>>> next(s) | |
19 | |
>>> next(s) | |
21 | |
>>> next(s) | |
23 | |
>>> next(s) | |
25 | |
>>> next(s) | |
27 | |
>>> next(s) | |
29 | |
>>> next(s) | |
31 | |
>>> next(s) | |
33 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment