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

Function solution

project_euler/problem_173/sol1.py:17–36  ·  view source on GitHub ↗

Return the number of different square laminae that can be formed using up to one million tiles. >>> solution(100) 41

(limit: int = 1000000)

Source from the content-addressed store, hash-verified

15
16
17def solution(limit: int = 1000000) -> int:
18 """
19 Return the number of different square laminae that can be formed using up to
20 one million tiles.
21 >>> solution(100)
22 41
23 """
24 answer = 0
25
26 for outer_width in range(3, (limit // 4) + 2):
27 if outer_width**2 > limit:
28 hole_width_lower_bound = max(ceil(sqrt(outer_width**2 - limit)), 1)
29 else:
30 hole_width_lower_bound = 1
31 if (outer_width - hole_width_lower_bound) % 2:
32 hole_width_lower_bound += 1
33
34 answer += (outer_width - hole_width_lower_bound - 2) // 2 + 1
35
36 return answer
37
38
39if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

ceilFunction · 0.90

Tested by

no test coverage detected