Created
February 21, 2015 21:03
-
-
Save rinfz/f093eb75ab2b1898e3cf to your computer and use it in GitHub Desktop.
erat
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 sieve(limit): | |
""" | |
Performs the Sieve of Eratosthenes | |
:return: A list of prime numbers less than a given limit | |
""" | |
numbers = [True] * (limit + 1) | |
for i in range(2, int(math.sqrt(limit))): | |
if numbers[i]: | |
j_increment = lambda j: [int(math.pow(j, 2) + (n * j)) for n in | |
itertools.takewhile(lambda x: int(math.pow(j, 2) + (x * j)) <= limit, | |
range(0, limit))] | |
for j in j_increment(i): | |
numbers[j] = False | |
return [i for i, j in enumerate(numbers) if j and i > 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment