From db841e474f7bff676804840d55968d83b9829eea Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 20 Dec 2020 10:25:23 +0100 Subject: [PATCH] day20: in p2 restrict p1 to only what we need --- day20.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/day20.py b/day20.py index 0d4dd9c..28496e6 100644 --- a/day20.py +++ b/day20.py @@ -74,7 +74,7 @@ def getAllPossibleBorders(tile_dict, exception): return all_possible_borders -def getCornerPieces(tile_dict): +def getCornerPieces(tile_dict, only_get_first_piece=False): corner_pieces = [] for tile_id, tile in tile_dict.items(): impossible_borders = 0 @@ -85,6 +85,8 @@ def getCornerPieces(tile_dict): # we need to find the tiles where 2 borders (and their reverse) don't match any other border if impossible_borders == 4: + if only_get_first_piece: + return tile_id corner_pieces.append(tile_id) return corner_pieces @@ -109,7 +111,7 @@ def part2(test_mode=False): borderlen = int(math.sqrt(len(tile_dict))) all_pieces = list(tile_dict.keys()) - corner_piece = getCornerPieces(tile_dict)[0] + corner_piece = getCornerPieces(tile_dict, only_get_first_piece=True) all_pieces.remove(corner_piece) # first - find correct orientation of corner piece