MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_116/sol1.py:38–60  ·  view source on GitHub ↗

Returns the number of different ways can the grey tiles in a row of the given length be replaced if colours cannot be mixed and at least one coloured tile must be used >>> solution(5) 12

(length: int = 50)

Source from the content-addressed store, hash-verified

36
37
38def solution(length: int = 50) -> int:
39 """
40 Returns the number of different ways can the grey tiles in a row
41 of the given length be replaced if colours cannot be mixed
42 and at least one coloured tile must be used
43
44 >>> solution(5)
45 12
46 """
47
48 different_colour_ways_number = [[0] * 3 for _ in range(length + 1)]
49
50 for row_length in range(length + 1):
51 for tile_length in range(2, 5):
52 for tile_start in range(row_length - tile_length + 1):
53 different_colour_ways_number[row_length][tile_length - 2] += (
54 different_colour_ways_number[row_length - tile_start - tile_length][
55 tile_length - 2
56 ]
57 + 1
58 )
59
60 return sum(different_colour_ways_number[length])
61
62
63if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected