forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sol1.py
53 lines (34 loc) · 1.5 KB
/
sol1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Project Euler Problem 117: https://projecteuler.net/problem=117
Using a combination of grey square tiles and oblong tiles chosen from:
red tiles (measuring two units), green tiles (measuring three units),
and blue tiles (measuring four units),
it is possible to tile a row measuring five units in length
in exactly fifteen different ways.
|grey|grey|grey|grey|grey| |red,red|grey|grey|grey|
|grey|red,red|grey|grey| |grey|grey|red,red|grey|
|grey|grey|grey|red,red| |red,red|red,red|grey|
|red,red|grey|red,red| |grey|red,red|red,red|
|green,green,green|grey|grey| |grey|green,green,green|grey|
|grey|grey|green,green,green| |red,red|green,green,green|
|green,green,green|red,red| |blue,blue,blue,blue|grey|
|grey|blue,blue,blue,blue|
How many ways can a row measuring fifty units in length be tiled?
NOTE: This is related to Problem 116 (https://projecteuler.net/problem=116).
"""
def solution(length: int = 50) -> int:
"""
Returns the number of ways can a row of the given length be tiled
>>> solution(5)
15
"""
ways_number = [1] * (length + 1)
for row_length in range(length + 1):
for tile_length in range(2, 5):
for tile_start in range(row_length - tile_length + 1):
ways_number[row_length] += ways_number[
row_length - tile_start - tile_length
]
return ways_number[length]
if __name__ == "__main__":
print(f"{solution() = }")