Created
August 27, 2020 22:02
-
-
Save ahmed4end/7968e4b5b303611eb31c555bd1ae5ed6 to your computer and use it in GitHub Desktop.
lazy way to find prime numbers
This file contains hidden or 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 inf(n): | |
yield n | |
yield from inf(n+1) | |
def prime(s): | |
n = next(s) | |
yield n | |
yield from prime(i for i in s if i%n!=0) | |
p = prime(inf(2)) | |
for i in range(100): | |
print(next(p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment