forked from dthinkcs/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsieve0.py
More file actions
24 lines (19 loc) · 643 Bytes
/
sieve0.py
File metadata and controls
24 lines (19 loc) · 643 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
Implement the Sieve of Eratosthenes
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
"""
def compute_primes(bound):
"""
Return a list of the prime numbers in range(2, bound)
"""
answer = list(range(2, bound))
for divisor in range(2, bound):
# remove all multiple of divisor from answer
for i in range(len(answer)):
if answer[i] != 1:
if answer[i] != divisor:
if answer[i] % divisor == 0:
answer[i] = 1
return([num for num in answer if num != 1])
print(len(compute_primes(200)))
print(len(compute_primes(2000)))