Skip to content

Fixed sieve #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pygorithm/math/sieve_of_eratosthenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def sieve_of_eratosthenes(n):
p = 2

while p * p <= n:
# if p is not marked as False, this it is a prime
# if p is not marked as False, it is a prime
if primes[p]:
# mark all the multiples of number as False
for i in range(p * 2, n + 1, p):
primes[i] = False
p += 1

# getting all primes
primes = [element for element in range(2, n) if primes[element]]
primes = [element for element in range(2, n + 1) if primes[element]]

return primes

Expand Down
2 changes: 1 addition & 1 deletion tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_lcm_using_gcd(self):

class TestSieveOfEratosthenes(unittest.TestCase):
def test_sieve_of_eratosthenes(self):
self.assertEqual(sieve_of_eratosthenes.sieve_of_eratosthenes(10), [2, 3, 5, 7])
self.assertEqual(sieve_of_eratosthenes.sieve_of_eratosthenes(11), [2, 3, 5, 7, 11])

class TestFactorial(unittest.TestCase):
def test_factorial(self):
Expand Down