Created
July 5, 2011 09:32
-
-
Save dexterous/1064555 to your computer and use it in GitHub Desktop.
prime number generator in python
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
def prime_generator(): | |
potential = 2 | |
primes = [] | |
while True: | |
while any(potential % x == 0 for x in primes): | |
potential += 1 | |
yield potential | |
primes.append(potential) | |
prime_numbers = prime_generator() | |
known_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23] | |
for n in known_primes: | |
assert prime_numbers.next() == n, n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SHA: 4583371527fa16f34bb57d639b7e2a56b47cad20
refactored as suggested by @dnene in https://gist.github.com/1064649