Skip to content

Commit 7958c44

Browse files
fix(web_programming): return '- ' when no <fin-streamer> tag found
1 parent 3d778d5 commit 7958c44

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

maths/sieve_of_atkin.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
from typing import List
1+
import math
22

33

4-
def sieve_of_atkin(limit: int) -> List[int]:
4+
def sieve_of_atkin(limit: int) -> list[int]:
55
"""
66
Compute all prime numbers up to the given limit using the Sieve of Atkin.
77
8-
Parameterss
8+
Parameters
99
----------
1010
limit : int
1111
Upper bound of primes to generate (inclusive).
1212
1313
Returns
1414
-------
15-
List[int]
15+
list[int]
1616
A list of prime numbers <= limit.
1717
1818
Raises
1919
------
2020
ValueError
21-
If limit is not an integer or is less than 2.
21+
If limit is not an integer >= 2.
2222
2323
References
2424
----------
@@ -30,20 +30,18 @@ def sieve_of_atkin(limit: int) -> List[int]:
3030
[2, 3, 5, 7]
3131
>>> sieve_of_atkin(1)
3232
Traceback (most recent call last):
33-
...
33+
...
3434
ValueError: limit must be an integer >= 2
3535
"""
3636
if not isinstance(limit, int) or limit < 2:
3737
raise ValueError("limit must be an integer >= 2")
3838

3939
# Initialize the sieve array
4040
sieve = [False] * (limit + 1)
41-
results: List[int] = []
41+
results: list[int] = []
4242

4343
# Preliminary marking based on quadratic forms
44-
from math import sqrt
45-
46-
sqrt_limit = int(sqrt(limit)) + 1
44+
sqrt_limit = int(math.sqrt(limit)) + 1
4745
for x in range(1, sqrt_limit):
4846
for y in range(1, sqrt_limit):
4947
n = 4 * x * x + y * y

maths/test_sieve_of_atkin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
# maths/test_sieve_of_atkin.py
21
import pytest
2+
33
from maths.sieve_of_atkin import sieve_of_atkin
44

55

66
def test_small_primes():
77
assert sieve_of_atkin(10) == [2, 3, 5, 7]
88

99

10+
def test_medium_primes():
11+
assert sieve_of_atkin(20) == [2, 3, 5, 7, 11, 13, 17, 19]
12+
13+
1014
def test_invalid_limit():
1115
with pytest.raises(ValueError):
1216
sieve_of_atkin(1)

0 commit comments

Comments
 (0)