File tree 2 files changed +41
-0
lines changed
project_euler/problem_173
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
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 () = } " )
You can’t perform that action at this time.
0 commit comments