Skip to content

Instantly share code, notes, and snippets.

@tiagocoutinho
Created September 6, 2020 11:01
Show Gist options
  • Save tiagocoutinho/dfdce65b7c70eb215458714c5599e620 to your computer and use it in GitHub Desktop.
Save tiagocoutinho/dfdce65b7c70eb215458714c5599e620 to your computer and use it in GitHub Desktop.
prime generator in python
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