Skip to content

Commit e33d6bb

Browse files
authored
Descriptive function/parameter name and type hints
1 parent 370cf6b commit e33d6bb

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

project_euler/problem_050/sol1.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,35 @@
1515
Which prime, below one-million, can be written as the sum of the most
1616
consecutive primes?
1717
"""
18+
from typing import List
1819

1920

20-
def sieve(n: int) -> list:
21+
def prime_sieve(limit: int) -> List[int]:
2122
"""
2223
Sieve of Erotosthenes
23-
Function to return all the prime numbers up to a certain number
24+
Function to return all the prime numbers up to a number 'limit'
2425
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
25-
>>> sieve(3)
26+
27+
>>> prime_sieve(3)
2628
[2]
2729
28-
>>> sieve(50)
30+
>>> prime_sieve(50)
2931
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
3032
"""
31-
is_prime = [True] * n
33+
is_prime = [True] * limit
3234
is_prime[0] = False
3335
is_prime[1] = False
3436
is_prime[2] = True
3537

36-
for i in range(3, int(n ** 0.5 + 1), 2):
38+
for i in range(3, int(limit ** 0.5 + 1), 2):
3739
index = i * 2
38-
while index < n:
40+
while index < limit:
3941
is_prime[index] = False
4042
index = index + i
4143

4244
primes = [2]
4345

44-
for i in range(3, n, 2):
46+
for i in range(3, limit, 2):
4547
if is_prime[i]:
4648
primes.append(i)
4749

@@ -62,7 +64,7 @@ def solution(ceiling: int = 1_000_000) -> int:
6264
>>> solution(10_000)
6365
9521
6466
"""
65-
primes = sieve(ceiling)
67+
primes = prime_sieve(ceiling)
6668
length = 0
6769
largest = 0
6870

0 commit comments

Comments
 (0)