Created
April 13, 2012 19:39
-
-
Save porcow/2379552 to your computer and use it in GitHub Desktop.
Prime Number Iterator
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
| def PrimeIter(num): | |
| seq = [ i for i in xrange(num) ] | |
| def gen(): | |
| for n in seq: | |
| if 2<=n<=num/2: | |
| yield n | |
| for s in gen(): | |
| for m in seq[s::s][1:]: | |
| seq[m] = 0 | |
| return ( r for r in seq if r!=0 and r>=2 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment