File tree Expand file tree Collapse file tree 1 file changed +0
-40
lines changed
project_euler/problem_073 Expand file tree Collapse file tree 1 file changed +0
-40
lines changed Original file line number Diff line number Diff line change 19
19
from math import gcd
20
20
21
21
22
- def slow_solution (max_d : int = 12_000 ) -> int :
23
- """
24
- Returns number of fractions lie between 1/3 and 1/2 in the sorted set
25
- of reduced proper fractions for d ≤ max_d
26
-
27
- >>> slow_solution(4)
28
- 0
29
-
30
- >>> slow_solution(5)
31
- 1
32
-
33
- >>> slow_solution(8)
34
- 3
35
- """
36
-
37
- fractions_number = 0
38
- for d in range (max_d + 1 ):
39
- for n in range (d // 3 + 1 , (d + 1 ) // 2 ):
40
- if gcd (n , d ) == 1 :
41
- fractions_number += 1
42
- return fractions_number
43
-
44
-
45
22
def solution (max_d : int = 12_000 ) -> int :
46
23
"""
47
24
Returns number of fractions lie between 1/3 and 1/2 in the sorted set
@@ -71,22 +48,5 @@ def solution(max_d: int = 12_000) -> int:
71
48
return fractions_number
72
49
73
50
74
- def benchmark () -> None :
75
- """
76
- Benchmarks
77
- """
78
- # Running performance benchmarks...
79
- # slow_solution : 21.02750190000006
80
- # solution : 15.79036830000041
81
-
82
- from timeit import timeit
83
-
84
- print ("Running performance benchmarks..." )
85
-
86
- print (f"slow_solution : { timeit ('slow_solution()' , globals = globals (), number = 10 )} " )
87
- print (f"solution : { timeit ('solution()' , globals = globals (), number = 10 )} " )
88
-
89
-
90
51
if __name__ == "__main__" :
91
52
print (f"{ solution () = } " )
92
- benchmark ()
You can’t perform that action at this time.
0 commit comments