From cd0f76a449c1383e7b1e839d04a754742330c4bd Mon Sep 17 00:00:00 2001 From: kamoshi <18511281+kamoshi@users.noreply.github.com> Date: Sun, 20 Dec 2020 21:28:56 +0100 Subject: [PATCH] Update day20.py --- 2020/Python/day20.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/2020/Python/day20.py b/2020/Python/day20.py index c84896a..509863f 100644 --- a/2020/Python/day20.py +++ b/2020/Python/day20.py @@ -170,3 +170,30 @@ DATA = parse_data() connect_tiles(DATA, set(), DATA[0].flip_ud()) print(solve_p1(DATA)) + +def render_full_image(data: list[Tile]) -> Tile: + # Find top-left corner + current_start: Union[None, Tile] = None + for tile in data: + if not tile.left and not tile.up and tile.right and tile.down: + current_start = tile + break + rendered = [[]] + while current_start: + for i in range(1, len(current_start.image[0])-1): + line = [] + line += current_start.image[i][1:-1] + + current_right = current_start.right + while current_right: # add line from the right side + line += current_right.image[i][1:-1] + current_right = current_right.right + + rendered.append(line) + current_start = current_start.down + + return Tile("RENDERED", rendered[1:]) + + +RENDERED = render_full_image(DATA) +RENDERED.print()