Last active
July 17, 2016 09:20
-
-
Save graph226/dc59373d0e6c6d3478f0252e45c75236 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes by Python
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
import math | |
NUMBER = 1000 | |
def prime_bool_list(num): | |
num_list = [True] * num | |
num_list[0] = num_list[1] = False | |
limit_sqrt = math.sqrt(num) | |
for count in xrange(2,num): | |
if count >= limit_sqrt: | |
return [i for i, b in enumerate(num_list) if b == True] | |
for composite in range(count ** 2, num, count): | |
num_list[composite] = False | |
print prime_bool_list(NUMBER) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment