Created
September 6, 2020 11:01
-
-
Save tiagocoutinho/dfdce65b7c70eb215458714c5599e620 to your computer and use it in GitHub Desktop.
prime generator in python
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 nats(n): | |
while True: | |
yield n | |
n += 1 | |
# another nats implementation | |
def nats2(n): | |
yield n | |
yield from nats2(n+1) | |
def sieve(stream): | |
n = next(stream) | |
yield n | |
yield from sieve(i for i in stream if i % n != 0) | |
def primes() | |
return sieve(nats(2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment