Skip to content

Instantly share code, notes, and snippets.

@bemasher
Created May 1, 2009 05:30
Show Gist options
  • Save bemasher/104890 to your computer and use it in GitHub Desktop.
Save bemasher/104890 to your computer and use it in GitHub Desktop.
#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