Skip to content

Instantly share code, notes, and snippets.

@alanduan
Created March 30, 2018 00:42
Show Gist options
  • Save alanduan/ef79f4e023be1be68658bd3a01daef5e to your computer and use it in GitHub Desktop.
Save alanduan/ef79f4e023be1be68658bd3a01daef5e to your computer and use it in GitHub Desktop.
import itertools
def prime():
primes = [2]
yield 2
for candidate in itertools.count(3):
if all(candidate % i != 0 for i in primes if i * i <= candidate):
primes.append(candidate)
yield candidate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment