Skip to content

Instantly share code, notes, and snippets.

@ahmed4end
Created August 27, 2020 22:02
Show Gist options
  • Save ahmed4end/7968e4b5b303611eb31c555bd1ae5ed6 to your computer and use it in GitHub Desktop.
Save ahmed4end/7968e4b5b303611eb31c555bd1ae5ed6 to your computer and use it in GitHub Desktop.
lazy way to find prime numbers
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