Skip to content

Commit

Permalink
Create problem5.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nocarend committed Feb 21, 2024
1 parent b8b92ff commit 5b826ef
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions problems-2/n-valikov/problem5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest


def solve(n: int) -> [int]:
return [number for number in range(2, n + 1)
if (number % 2
and all([number % divisor
for divisor in range(3, int(number ** 0.5) + 1, 2)])
or number == 2)]


class TestPrimes(unittest.TestCase):
def test_solution(self):
self.assertEqual(solve(1), [])
self.assertEqual(solve(10), [2, 3, 5, 7])
self.assertEqual(solve(100), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97])


if __name__ == '__main__':
unittest.main()

0 comments on commit 5b826ef

Please sign in to comment.