day20: in p2 restrict p1 to only what we need
This commit is contained in:
parent
0098cac688
commit
db841e474f
6
day20.py
6
day20.py
@ -74,7 +74,7 @@ def getAllPossibleBorders(tile_dict, exception):
|
|||||||
return all_possible_borders
|
return all_possible_borders
|
||||||
|
|
||||||
|
|
||||||
def getCornerPieces(tile_dict):
|
def getCornerPieces(tile_dict, only_get_first_piece=False):
|
||||||
corner_pieces = []
|
corner_pieces = []
|
||||||
for tile_id, tile in tile_dict.items():
|
for tile_id, tile in tile_dict.items():
|
||||||
impossible_borders = 0
|
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
|
# we need to find the tiles where 2 borders (and their reverse) don't match any other border
|
||||||
if impossible_borders == 4:
|
if impossible_borders == 4:
|
||||||
|
if only_get_first_piece:
|
||||||
|
return tile_id
|
||||||
corner_pieces.append(tile_id)
|
corner_pieces.append(tile_id)
|
||||||
|
|
||||||
return corner_pieces
|
return corner_pieces
|
||||||
@ -109,7 +111,7 @@ def part2(test_mode=False):
|
|||||||
|
|
||||||
borderlen = int(math.sqrt(len(tile_dict)))
|
borderlen = int(math.sqrt(len(tile_dict)))
|
||||||
all_pieces = list(tile_dict.keys())
|
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)
|
all_pieces.remove(corner_piece)
|
||||||
|
|
||||||
# first - find correct orientation of corner piece
|
# first - find correct orientation of corner piece
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user