MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_174/sol1.py:24–50  ·  view source on GitHub ↗

Return the sum of N(n) for 1 <= n <= n_limit. >>> solution(1000,5) 222 >>> solution(1000,10) 249 >>> solution(10000,10) 2383

(t_limit: int = 1000000, n_limit: int = 10)

Source from the content-addressed store, hash-verified

22
23
24def solution(t_limit: int = 1000000, n_limit: int = 10) -> int:
25 """
26 Return the sum of N(n) for 1 <= n <= n_limit.
27
28 >>> solution(1000,5)
29 222
30 >>> solution(1000,10)
31 249
32 >>> solution(10000,10)
33 2383
34 """
35 count: defaultdict = defaultdict(int)
36
37 for outer_width in range(3, (t_limit // 4) + 2):
38 if outer_width * outer_width > t_limit:
39 hole_width_lower_bound = max(
40 ceil(sqrt(outer_width * outer_width - t_limit)), 1
41 )
42 else:
43 hole_width_lower_bound = 1
44
45 hole_width_lower_bound += (outer_width - hole_width_lower_bound) % 2
46
47 for hole_width in range(hole_width_lower_bound, outer_width - 1, 2):
48 count[outer_width * outer_width - hole_width * hole_width] += 1
49
50 return sum(1 for n in count.values() if 1 <= n <= n_limit)
51
52
53if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

ceilFunction · 0.90

Tested by

no test coverage detected