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 1919from math import gcd
2020
2121
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-
4522def solution (max_d : int = 12_000 ) -> int :
4623 """
4724 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:
7148 return fractions_number
7249
7350
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-
9051if __name__ == "__main__" :
9152 print (f"{ solution () = } " )
92- benchmark ()
You can’t perform that action at this time.
0 commit comments