Last active
April 23, 2017 14:24
-
-
Save codysoyland/7164035 to your computer and use it in GitHub Desktop.
A prime number generator using Python generators, inspired by concurrent prime sieve at http://play.golang.org/p/9U22NfrXeq
This file contains hidden or 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
from itertools import count | |
def filter(input, prime): | |
for i in input: | |
if i % prime: | |
yield i | |
def get_primes(num): | |
g = count(2) | |
for _ in xrange(num): | |
prime = g.next() | |
yield prime | |
g = filter(g, prime) | |
for num in get_primes(10): | |
print num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment