Skip to content

Instantly share code, notes, and snippets.

@luabida
Created January 3, 2023 14:48
Show Gist options
  • Select an option

  • Save luabida/c8354e123e425dee4704a8b56b8b496c to your computer and use it in GitHub Desktop.

Select an option

Save luabida/c8354e123e425dee4704a8b56b8b496c to your computer and use it in GitHub Desktop.
Recursion & Laziness Evaluation | First 100 positive prime numbers
def positives(n):
yield n
yield from positives(n+1)
def primes(s):
n = next(s)
yield n
yield from primes(i for i in s if i%n != 0)
p = primes(positives(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