Skip to content

Instantly share code, notes, and snippets.

@graph226
Last active July 17, 2016 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save graph226/dc59373d0e6c6d3478f0252e45c75236 to your computer and use it in GitHub Desktop.
Save graph226/dc59373d0e6c6d3478f0252e45c75236 to your computer and use it in GitHub Desktop.
Sieve of Eratosthenes by Python
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