Skip to content

Commit 8298470

Browse files
committed
Fix issues
1 parent 30aabe7 commit 8298470

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

project_euler/problem_073/sol1.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from math import gcd
2020

21+
2122
def slow_solution(max_d: int = 12_000) -> int:
2223
"""
2324
Returns number of fractions lie between 1/3 and 1/2 in the sorted set
@@ -40,6 +41,7 @@ def slow_solution(max_d: int = 12_000) -> int:
4041
fractions_number += 1
4142
return fractions_number
4243

44+
4345
def solution(max_d: int = 12_000) -> int:
4446
"""
4547
Returns number of fractions lie between 1/3 and 1/2 in the sorted set
@@ -58,10 +60,7 @@ def solution(max_d: int = 12_000) -> int:
5860
fractions_number = 0
5961
for d in range(max_d + 1):
6062
if d % 2 == 0:
61-
if (d // 3 + 1) % 2 == 0:
62-
n_start = d // 3 + 2
63-
else:
64-
n_start = d // 3 + 1
63+
n_start = d // 3 + 2 if (d // 3 + 1) % 2 == 0 else d // 3 + 1
6564
for n in range(n_start, (d + 1) // 2, 2):
6665
if gcd(n, d) == 1:
6766
fractions_number += 1
@@ -71,6 +70,7 @@ def solution(max_d: int = 12_000) -> int:
7170
fractions_number += 1
7271
return fractions_number
7372

73+
7474
def benchmark() -> None:
7575
"""
7676
Benchmarks
@@ -86,6 +86,7 @@ def benchmark() -> None:
8686
print(f"slow_solution : {timeit('slow_solution()', globals=globals(), number=10)}")
8787
print(f"solution : {timeit('solution()', globals=globals(), number=10)}")
8888

89+
8990
if __name__ == "__main__":
9091
print(f"{solution() = }")
9192
benchmark()

0 commit comments

Comments
 (0)