Created
August 15, 2012 13:00
-
-
Save lyricat/3359927 to your computer and use it in GitHub Desktop.
prime sieve
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 Generate(): | |
i = 2 | |
while True: | |
yield i | |
i += 1 | |
def Filter(ig, prime): | |
while True: | |
i = ig.next() | |
if i % prime != 0: | |
yield i | |
if __name__ == "__main__": | |
ig = Generate() | |
for i in range (0, 20): | |
prime = ig.next() | |
print prime | |
primeg = Filter(ig, prime) | |
ig = primeg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment