Skip to content

Commit 2226db4

Browse files
committed
follow conventions
1 parent 7c648a6 commit 2226db4

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

project_euler/problem_108/sol1.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@
2525
"""
2626

2727

28-
def find_primes(n: int) -> list[int]:
28+
def find_primes(limit: int) -> list[int]:
2929
"""
30-
Returns a list of all primes less than or equal to n
30+
Returns a list of all primes less than or equal to 'limit'
3131
>>> find_primes(19)
3232
[2, 3, 5, 7, 11, 13, 17, 19]
3333
"""
34-
sieve = [True] * (n + 1)
34+
sieve = [True] * (limit + 1)
3535

36-
for i in range(2, n + 1):
37-
for j in range(2 * i, n + 1, i):
36+
for i in range(2, limit + 1):
37+
for j in range(2 * i, limit + 1, i):
3838
sieve[j] = False
39-
return [i for i in range(2, n + 1) if sieve[i]]
39+
return [i for i in range(2, limit + 1) if sieve[i]]
4040

4141

42-
def find_prime_factorizations(n: int) -> list[dict[int, int]]:
42+
def find_prime_factorizations(limit: int) -> list[dict[int, int]]:
4343
"""
4444
Returns a list of prime factorizations of 2...n, with prime
4545
factorization represented as a dictionary of (prime, exponent) pairs
4646
>>> find_prime_factorizations(7)
4747
[{}, {}, {2: 1}, {3: 1}, {2: 2}, {5: 1}, {2: 1, 3: 1}, {7: 1}]
4848
"""
49-
primes = find_primes(n)
50-
prime_factorizations = [{} for _ in range(n + 1)]
49+
primes = find_primes(limit)
50+
prime_factorizations = [{} for _ in range(limit + 1)]
5151

5252
for p in primes:
53-
for j in range(p, n + 1, p):
53+
for j in range(p, limit + 1, p):
5454
j_factorization = prime_factorizations[j]
5555
x = j
5656
while x % p == 0:
@@ -82,11 +82,9 @@ def solution(target: int = 1000) -> int:
8282
upper_bound = 210 ** ((int((2 * target - 1) ** 0.25) + 1) // 2)
8383
prime_factorizations = find_prime_factorizations(upper_bound)
8484

85-
def num_solutions(n):
86-
return (num_divisors_of_square(prime_factorizations[n]) // 2) + 1
87-
8885
for i in range(2, upper_bound + 1):
89-
if num_solutions(i) > target:
86+
num_solutions = (num_divisors_of_square(prime_factorizations[i]) // 2) + 1
87+
if num_solutions > target:
9088
return i
9189

9290

0 commit comments

Comments
 (0)