day20: in p2 restrict p1 to only what we need

This commit is contained in:
Stefan Harmuth 2020-12-20 10:25:23 +01:00
parent 0098cac688
commit db841e474f

View File

@ -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