Skip to content

Commit e30b0da

Browse files
authored
Add solution for Project Euler problem 173. (TheAlgorithms#3075)
* Added solution for Project Euler problemm problem 173. TheAlgorithms#2695 * Added docstring * Update formatting, doctest and annotations. Reference: TheAlgorithms#3256
1 parent f8a907d commit e30b0da

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Diff for: project_euler/problem_173/__init__.py

Whitespace-only changes.

Diff for: project_euler/problem_173/sol1.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Project Euler Problem 173: https://projecteuler.net/problem=173
3+
4+
We shall define a square lamina to be a square outline with a square "hole" so that
5+
the shape possesses vertical and horizontal symmetry. For example, using exactly
6+
thirty-two square tiles we can form two different square laminae:
7+
8+
With one-hundred tiles, and not necessarily using all of the tiles at one time, it is
9+
possible to form forty-one different square laminae.
10+
11+
Using up to one million tiles how many different square laminae can be formed?
12+
"""
13+
14+
15+
from math import ceil, sqrt
16+
17+
18+
def solution(limit: int = 1000000) -> int:
19+
"""
20+
Return the number of different square laminae that can be formed using up to
21+
one million tiles.
22+
>>> solution(100)
23+
41
24+
"""
25+
answer = 0
26+
27+
for outer_width in range(3, (limit // 4) + 2):
28+
if outer_width ** 2 > limit:
29+
hole_width_lower_bound = max(ceil(sqrt(outer_width ** 2 - limit)), 1)
30+
else:
31+
hole_width_lower_bound = 1
32+
if (outer_width - hole_width_lower_bound) % 2:
33+
hole_width_lower_bound += 1
34+
35+
answer += (outer_width - hole_width_lower_bound - 2) // 2 + 1
36+
37+
return answer
38+
39+
40+
if __name__ == "__main__":
41+
print(f"{solution() = }")

0 commit comments

Comments
 (0)