Count valid pipe boards

Write codeMedium28 min

Your task

A puzzle game ships a board of pipe tiles and the level tool has to know how many finished boards exist. tile_rows gives the board one row at a time, every row the same width, and each entry is four characters reading a tile's open ends clockwise from the top, north then east then south then west, where 1 is an open end and 0 is a wall, so 0110 is open on the east and the south. A player may turn a tile to any of its four quarter turns. A board is finished when every open end meets an open end on the neighbouring tile and no open end points off the board. Two finished boards are the same when every square shows the same four characters, so turning a tile that reads the same after a quarter turn does not make a new board. Return how many finished boards exist. The board is at most 4 by 4.

Examples

count_pipe_layouts(tile_rows: list[list[str]]) -> int
Example 1
Inputcount_pipe_layouts([["1100", "1100"], ["1100", "1100"]])
Output1
Example 2
Inputcount_pipe_layouts([["1000", "1000"], ["1000", "1000"]])
Output2
Example 3
Inputcount_pipe_layouts([["0000", "0000"], ["0000", "0000"]])
Output1