Created
November 17, 2014 23:43
-
-
Save Isweet/d458b6d00cbf564d56c0 to your computer and use it in GitHub Desktop.
Generate an arbitrary number of primes
This file contains 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
import itertools | |
def prime_gen(): | |
yield 2 | |
curr = 3 | |
seen = [2] | |
while (True): | |
yield curr | |
seen.append(curr) | |
curr = next((x for x in itertools.count(curr + 2, 2) if all(x % i != 0 for i in seen)), None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment