Skip to content
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