Created
May 1, 2009 05:30
-
-
Save bemasher/104890 to your computer and use it in GitHub Desktop.
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
#Sieve of Eratosthenes | |
def GetPrimes(p, i=1): | |
if i**2 < p[-1]: | |
p[i:] = filter(lambda x: x % p[i-1] != 0, p[i:]) | |
return GetPrimes(p, i + 1) | |
return p | |
print GetPrimes(range(2,51)) | |
#[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment