From 10ffd11c4673a4c89faf8d85f38793c9d4479156 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 20 Dec 2020 10:18:12 +0100 Subject: [PATCH] day20: raw (ugly) version --- aoclib/output.py | 4 +- day20.py | 223 ++++++ inputs/20 | 1727 ++++++++++++++++++++++++++++++++++++++++++++++ inputs/20_test | 107 +++ main.py | 12 +- 5 files changed, 2070 insertions(+), 3 deletions(-) create mode 100644 day20.py create mode 100644 inputs/20 create mode 100644 inputs/20_test diff --git a/aoclib/output.py b/aoclib/output.py index 9f7363a..0037255 100644 --- a/aoclib/output.py +++ b/aoclib/output.py @@ -1,5 +1,7 @@ -def printSolution(day, part, solution, test=False): +def printSolution(day, part, solution, test=None): if test: print("(TEST) ", end="") print("Solution to day %s, part %s: %s" % (day, part, solution)) + if test: + print("Expected: %s (%s)" % (test, "correct" if test == solution else "WRONG")) diff --git a/day20.py b/day20.py new file mode 100644 index 0000000..22f335d --- /dev/null +++ b/day20.py @@ -0,0 +1,223 @@ +import aoclib +import math +import re + +DAY = 20 +TEST_SOLUTION_PART1 = 20899048083289 +TEST_SOLUTION_PART2 = 273 + + +class Tile: + def __init__(self, raw_input): + self.image_id = int(raw_input[0][5:-1]) + self.image = raw_input[1:] + + def getPossibleBorderList(self): + return [ + self.image[0], + "".join([x[0] for x in self.image]), + "".join([x[-1] for x in self.image]), + self.image[-1], + "".join(reversed(self.image[0])), + "".join(reversed([x[0] for x in self.image])), + "".join(reversed([x[-1] for x in self.image])), + "".join(reversed(self.image[-1])), + ] + + def getBorderlessImage(self): + return ["".join(x for x in y[1:-1]) for y in self.image[1:-1]] + + def getCurrentBorders(self): + # top right bottom left + return [ + self.image[0], + "".join([x[-1] for x in self.image]), + self.image[-1], + "".join([x[0] for x in self.image]) + ] + + def rotateRight(self): + self.image = rotateRight(self.image) + + def rotateLeft(self): + self.image = rotateLeft(self.image) + + def flipHorizontally(self): + self.image = flipHorizontally(self.image) + + def flipVertically(self): + self.image = flipVertically(self.image) + + +def rotateRight(image): + return ["".join([x[line_no] for x in reversed(image)]) for line_no in range(len(image))] + + +def rotateLeft(image): + return ["".join([x[line_no] for x in image]) for line_no in reversed(range(len(image)))] + + +def flipHorizontally(image): + return list(reversed(image)) + + +def flipVertically(image): + return ["".join(x for x in reversed(y)) for y in image] + + +def getAllPossibleBorders(tile_dict, exception): + all_possible_borders = [] + for tile_id, tile in tile_dict.items(): + if tile_id != exception: + all_possible_borders.extend(tile.getPossibleBorderList()) + + return all_possible_borders + + +def getCornerPieces(tile_dict): + corner_pieces = [] + for tile_id, tile in tile_dict.items(): + impossible_borders = 0 + all_other_borders = getAllPossibleBorders(tile_dict, tile_id) + for border in tile.getPossibleBorderList(): + if border not in all_other_borders: + impossible_borders += 1 + + # we need to find the tiles where 2 borders (and their reverse) don't match any other border + if impossible_borders == 4: + corner_pieces.append(tile_id) + + return corner_pieces + + +def part1(test_mode=False): + my_input = aoclib.getMultiLineInputAsArray(day=DAY, test=test_mode) + tile_dict = {} + for tile_input in my_input: + tile = Tile(tile_input) + tile_dict[tile.image_id] = tile + + return math.prod(getCornerPieces(tile_dict)) + + +def part2(test_mode=False): + my_input = aoclib.getMultiLineInputAsArray(day=DAY, test=test_mode) + tile_dict = {} + for tile_input in my_input: + tile = Tile(tile_input) + tile_dict[tile.image_id] = tile + + borderlen = int(math.sqrt(len(tile_dict))) + all_pieces = list(tile_dict.keys()) + corner_piece = getCornerPieces(tile_dict)[0] + all_pieces.remove(corner_piece) + + # first - find correct orientation of corner piece + possible_borders = getAllPossibleBorders(tile_dict, corner_piece) + found = False + for _ in range(2): + for _ in range(2): + for _ in range(4): + if tile_dict[corner_piece].getCurrentBorders()[0] not in possible_borders \ + and tile_dict[corner_piece].getCurrentBorders()[3] not in possible_borders: + found = True + break + + tile_dict[corner_piece].rotateRight() + + if found: + break + else: + tile_dict[corner_piece].flipHorizontally() + + if found: + break + else: + tile_dict[corner_piece].flipVertically() + + # flip diagonally to match with example from aoc webpage + tile_dict[corner_piece].rotateRight() + tile_dict[corner_piece].flipVertically() + + full_image = [] + for y in range(borderlen): + full_image.append([]) + for x in range(borderlen): + if x == 0 and y == 0: + full_image[y].append(corner_piece) + continue + + # find matching piece with correct orientation for the piece to the left (or the top if y > 0 and x == 0) + if x == 0: # check against bottom border of upper piece + check_border = tile_dict[full_image[y - 1][x]].getCurrentBorders()[2] + else: + check_border = tile_dict[full_image[y][x - 1]].getCurrentBorders()[1] + + for possible_tile in all_pieces: + if check_border in tile_dict[possible_tile].getPossibleBorderList(): + # found my piece ... now orientate it correctly + oriented = False + for _ in range(2): + for _ in range(2): + for _ in range(4): + if (x == 0 and tile_dict[possible_tile].getCurrentBorders()[0] == check_border)\ + or (x != 0 and tile_dict[possible_tile].getCurrentBorders()[3] == check_border): + oriented = True + full_image[y].append(possible_tile) + all_pieces.remove(possible_tile) + break + + tile_dict[possible_tile].rotateRight() + + if oriented: + break + else: + tile_dict[possible_tile].flipVertically() + + if oriented: + break + else: + tile_dict[possible_tile].flipHorizontally() + + # now that we have the full picture, assemble the borderless full image + borderless_image = [] + full_hash_count = 0 + for y in full_image: + for image_line in range(8): + borderless_image.append("".join([tile_dict[x].getBorderlessImage()[image_line] for x in y])) + full_hash_count += borderless_image[-1].count('#') + + # and finally scan for our sea monster + # seamonster_line_1 = re.compile(r"..................#.") + seamonster_line_2 = re.compile(r"#....##....##....###") + seamonster_line_3 = re.compile(r".#..#..#..#..#..#...") + seamonster_hashcount = 15 # amount of '#' in the sea monster + seamonster_count = 0 + for _ in range(2): + for _ in range(2): + for _ in range(4): + for x in range(len(borderless_image) - 2): + if s_2 := re.split(seamonster_line_2, borderless_image[x+1]): + if s_3 := re.split(seamonster_line_3, borderless_image[x+2]): + # yes, this is somewhat optimistic, but it results in the correct answer + if len(s_2) > 1 and len(s_2) == len(s_3): + seamonster_count += len(s_2) - 1 + + if seamonster_count == 0: + borderless_image = rotateRight(borderless_image) + else: + break + + if seamonster_count == 0: + borderless_image = flipHorizontally(borderless_image) + else: + break + + if seamonster_count == 0: + borderless_image = flipVertically(borderless_image) + else: + break + + print(seamonster_count) + + return full_hash_count - seamonster_count * seamonster_hashcount diff --git a/inputs/20 b/inputs/20 new file mode 100644 index 0000000..a605d5e --- /dev/null +++ b/inputs/20 @@ -0,0 +1,1727 @@ +Tile 3301: +##..#...#. +.....#...# +#...#...## +#....#...# +#....#.#.. +.#..#.#.## +.........# +##...#.... +#...##...# +#..#..#.## + +Tile 2861: +..#..##### +.....##... +......#..# +...###...# +#......#.. +#.#....... +.........# +#......... +...#.#.... +....#..##. + +Tile 1459: +###.#.#... +#......... +#......... +#....#...# +#......... +#.....##.. +#.....#... +.#.#...#.# +#.#....... +##.###..#. + +Tile 2797: +....#####. +#..#...... +#.......#. +#....#...# +....#...#. +#........# +......#..# +#...#....# +.....##... +##..##.### + +Tile 2647: +###...###. +#......#.. +...##..... +..#.....## +.###..#..# +#..#...#.. +....##.... +#..#.....# +.......... +#..#....#. + +Tile 1733: +.#...###.# +#.#..#.... +.....#...# +....#..... +##..#..... +...#..#..# +...#.#.#.. +#......... +#.......## +########.. + +Tile 2999: +...##.#### +..#....... +#.....#... +##......#. +..#......# +##.....#.. +#..##....# +......#... +.#..#.#... +.......#.. + +Tile 3067: +.#..#..... +.#....#..# +#.##....#. +....#....# +...#....#. +##........ +#.......#. +.......... +#........# +..#.#.#.## + +Tile 3847: +######.#.# +......#..# +#..#.....# +#.#..#..#. +.#...###.. +##....#..# +#..#...... +......#... +.......... +##.##...#. + +Tile 1483: +.#........ +....#....# +#......... +##..#....# +...#...##. +#..#...... +...#...... +#.....#... +#......... +##.#.#.#.# + +Tile 1327: +######..#. +#...##.... +##.#....#. +##..##.... +##...#.#.# +#.#.#...## +#...#...#. +##...#.... +#.#......# +.##.####.. + +Tile 2423: +###..#.... +#...#..##. +.....#.... +...#..#..# +....#....# +....##.... +#..#..#.#. +.....#...# +.###..#..# +..##.###.. + +Tile 2689: +##.###..#. +##......## +#........# +.#...#..#. +#......... +.......... +#....#.... +##.......# +.....#..## +#..#.....# + +Tile 3049: +####...### +#.#......# +......#... +..#..#..#. +#.#.##..#. +.####..##. +...#.....# +......#..# +##...#.#.. +...###.#.# + +Tile 3121: +.#####.#.# +##.......# +#........# +.........# +.#........ +#......#.. +#....##... +......#... +.....#...# +#####..### + +Tile 2857: +..#..#.##. +..#..#.... +...#.#.... +#...#.#.## +#...#.#..# +...#...... +....#.#... +.#...###.# +.#..##.... +....##.#.# + +Tile 1399: +#....##..# +#..#.....# +#.....##.# +........#. +#.....#.## +.#.....#.# +#......#.. +.#..#...#. +#...#..#.. +##...###.# + +Tile 3371: +.#.##...## +.......... +..#....... +#..#...... +#....#...# +##........ +##.#...... +...###...# +...#...... +####..#..# + +Tile 2011: +#######... +..#..#..## +........#. +#...#..... +#......... +......#... +..#..#.... +.........# +#...##..## +.#..###.#. + +Tile 1321: +#..#....#. +.#...#...# +#..#...... +.##....... +.#.#..##.# +.......... +....#..... +#.##.....# +....####.. +.#####...# + +Tile 2341: +.#.#...#.. +###...#... +#.#.#..#.# +#.##.###.# +#......##. +..#.#.#..# +#...#..##. +#.#.....#. +#....#.#.. +#####.#### + +Tile 2029: +.##.####.. +#......... +.#...##.#. +....#....# +##.##....# +#...#....# +#....#..#. +#.......#. +#........# +.####.#..# + +Tile 1847: +####.####. +###....... +#......... +.........# +.#.#...... +#.##...#.. +#..#...... +#.#.....#. +.....#...# +.....#.#.. + +Tile 2833: +..#....... +.......#.# +.......#.# +#.......## +#..#...### +.##......# +.......### +#....#.#.. +.......#.. +###.#..... + +Tile 3769: +..#..#..## +....#..... +.#...#...# +..#..#.... +...##..... +#.##...... +.##...##.# +#.#.#..... +.#..##.... +##..##.### + +Tile 1621: +####..#... +#..#.#...# +......#..# +##...#.... +#..##..... +..#..#...# +..#.##.### +#.#...#..# +#.#....... +##.#.##.#. + +Tile 3557: +..#.##..#. +.....##... +#.....##.. +#.#.#.#... +#....#.... +#...#..#.. +##.#.....# +......#.#. +#......... +.#..##.... + +Tile 2539: +##.##.##.. +#....#.#.. +#..#....#. +#......#.# +#...##...# +........## +.......... +.....#...# +..#.##.... +..#...#... + +Tile 2309: +..#.##.... +#....#...# +#..#...... +..#....... +#...##.... +#........# +......#..# +.#.#...... +#..#.....# +....#.##.. + +Tile 1613: +.#....#### +#.#...#.## +#......... +#......... +.......... +#..#.....# +.........# +#......#.# +........#. +#.##...##. + +Tile 2791: +#.###..##. +.#........ +#......#.. +.......### +.##....... +##........ +........#. +##........ +.....#.#.# +......#### + +Tile 2957: +#.###.#... +#..#.....# +....#....# +#........# +....#..... +##.#...### +......#..# +#.#......# +#......#.. +.#..#.#... + +Tile 2803: +###....##. +..#.#..#.. +......#... +....#..... +#......##. +##......## +#....#.#.# +..#....### +#..##.#..# +..####..## + +Tile 2917: +.#.##..### +...#...... +#.#......# +#.....#..# +######.#.# +.......... +......#... +.....#.... +##.###.... +##.#...##. + +Tile 1487: +..#...#.#. +#........# +.#.#...... +#......... +####.#..#. +#..#.#...# +#.....##.# +..#....### +.........# +##.....#.# + +Tile 3389: +#.##..#.#. +........#. +.......... +#......#.# +.#.#...... +#....#.#.. +##....#... +#.#...#... +#......#.. +#..##....# + +Tile 3229: +##...##... +##.......# +#.##.....# +..#..#...# +....#.##.# +....#..#.. +#.....#... +##.##.#.## +.#........ +.#.##.###. + +Tile 1123: +#..#.###.. +#........# +#.#...#..# +##....#.#. +.......... +.#........ +#..#.##... +.......#.# +###.##..#. +.#..#.#.#. + +Tile 1279: +..##..#..# +........## +#.#......# +#..#.....# +...#...... +..#.....## +#....#.... +#...#....# +###....#.# +###..#..## + +Tile 3917: +.#..##.#.# +........## +..#..#..#. +#..##...## +#......... +......#... +#.....#..# +#.#......# +...#..##.# +##.###.##. + +Tile 2741: +##.#.##### +..##...... +...##..#.# +#..#.#.... +##..#..... +.#.....#.. +##....#..# +##.....#.# +#........# +.#.####.## + +Tile 1913: +.##...##.. +##.....#.# +.#..#..### +#........# +......###. +#....##..# +....#....# +###...#..# +##.......# +##.#.###.. + +Tile 1019: +...##.#..# +#..#.....# +.......... +.......... +##.####..# +#......### +#......### +#..#.....# +#.......## +.#.######. + +Tile 1223: +#.##....#. +..#...#..# +#........# +.........# +........#. +...#...... +..##..#... +.#...##.#. +..#.#.#..# +.#.....### + +Tile 1481: +#.#.#####. +.......#.. +.#..#..#.# +#.#..##..# +#.....#... +#.#...#... +....#....# +..#....... +....#..... +##..#...## + +Tile 3251: +#.#...###. +...##....# +##....#... +#.....##.# +#.......## +..###...#. +##..#..#.# +#.#....#.. +#....##..# +#.##.....# + +Tile 3863: +.#.##..... +.##...#.#. +#.......## +#.#....... +.#..#.#.#. +...###...# +#...#.#... +......#... +......#..# +.#..##.#.# + +Tile 3109: +..##.###.. +#..#.#.... +#...#...#. +...####... +....#..... +#....#..#. +.#...#...# +#..#..#... +...#..##.# +..##.#.... + +Tile 3023: +#...#...#. +...#.....# +.......#.# +#..##..... +.#.......# +.......#.# +..#...##.# +......#... +#.......#. +#.##..#### + +Tile 3391: +#.###...## +.#.#.....# +###......# +#.###..... +#.#......# +#...#.#..# +####.##... +.#..###..# +.#........ +#.#.#.##.. + +Tile 1811: +.......##. +..#...##.# +.###.....# +##.#.#.... +####...... +#.#....... +#........# +#...#..... +..#.#....# +..#.#....# + +Tile 2819: +.#.####### +#.....#... +.#..#....# +.........# +#...#.##.# +#..#...#.. +###..#.### +..#..###.. +.......#.. +##.##....# + +Tile 3209: +.##..#.#.# +.........# +#......... +#......... +.#....#..# +#.....#..# +......#..# +##.#.....# +#....#.#.# +#.##..###. + +Tile 3989: +#.#.#.#.#. +...#..#.#. +#......... +....#.#..# +.##.#.#..# +.....##.#. +#........# +#......### +#.#..#.... +.##.#..##. + +Tile 1831: +.##.#..#.. +...#...... +.......... +#..#..#... +.#.#..#... +#...#..#.# +...##..... +..###..... +...#.#...# +##.#.##... + +Tile 1801: +#.#...#.#. +.......... +...#...... +....#....# +#.....#... +.........# +##.#....#. +#......... +##.......# +.#.#....#. + +Tile 2143: +.#.#...#.# +#.#....... +...###...# +#......... +#..#...... +.........# +#.#.#..... +....#..#.# +..#.#..... +#.#.##.... + +Tile 3517: +.###.#...# +#.#.#..... +.#.......# +.........# +.........# +#.....##.. +.......... +#......#.# +#........# +..#.#..##. + +Tile 2287: +#####...#. +......#... +##........ +....#....# +.#........ +.##...###. +.##.....#. +.......... +........## +.#..#..#.. + +Tile 3221: +.###.##.## +##........ +.....##..# +#.......#. +........#. +##........ +....#..... +....#..... +##......#. +##.#.#.### + +Tile 3203: +###.##...# +.##.....#. +#......... +#.#....... +...#...... +#.#..#.#.. +#......... +#......#.# +.........# +####.#.... + +Tile 2707: +.#.....### +.....#.#.. +##..#..... +##....##.# +....#..### +.#..#.#... +#.....#... +#......#.. +.#.#...##. +#.##.##... + +Tile 3701: +.#.##..... +##....#..# +......#... +.......#.. +#...#...## +.....#.... +.#.#...#.# +#.#......# +###...#... +...#...#.# + +Tile 3709: +..#..#.... +.........# +#.#....... +#.#..#...# +##..#..#.. +.......... +#..#....#. +.....#.... +##........ +.###.....# + +Tile 2113: +..#..##.#. +#.#..#..#. +###......# +#..##.##.. +...#.....# +......#..# +#.....#.## +...#...#.. +.#..#....# +#..#.....# + +Tile 1091: +#..#...#.. +#.....#..# +...#...... +..#...#..# +.####..#.. +....#...## +..##.....# +#....#...# +....##.... +#.##....#. + +Tile 3671: +##.##...## +#.#....... +.........# +.#.......# +..#..#..## +.........# +#.....#.## +#.#....... +#......#.# +#.#..#.... + +Tile 3457: +#..#.###.. +#.....#..# +.....#...# +...#....#. +..#....... +#....#...# +#......... +..#.#..... +...##.#..# +.....#..## + +Tile 1229: +####.###.# +.......#.. +##.....#.. +...#.....# +#...#....# +#.#.#....# +#..#...#.# +#.#....#.# +....#..### +..#.#.###. + +Tile 1901: +.#.......# +..#.#....# +..#....... +##.#...### +.#.....#.. +....##.... +#..#...... +#.#....... +#.#....... +.#....#.#. + +Tile 2207: +...#..#..# +#..#.....# +...#...... +.........# +.....#..#. +#..#..#... +#...#.#.#. +.....#.#.. +#...##.... +.##.#...#. + +Tile 2531: +#.....#.## +...###.... +#........# +#......#.. +#....##..# +#......... +##........ +.#........ +.........# +.##....#.# + +Tile 1129: +##..###.#. +.#.##..... +#.#....... +#.#.#..... +#...#..#.# +.#...##..# +#...##..## +....#..... +.........# +###.##.... + +Tile 2477: +.##...#... +##......## +...#.....# +#......... +#........# +........#. +#...#.#..# +#.##..#... +.......#.. +....#####. + +Tile 1879: +...#...#.# +.##...##.. +..#..#.##. +....#...#. +#......#.# +#...##.... +.#.##..... +..#.#.#... +#...#....# +##...#..## + +Tile 3329: +.#..#.#.#. +##....#... +...#...... +##......## +.......... +#..#..#..# +.#...#.#.. +#......#.. +#.....#.## +#.##...#.# + +Tile 3083: +####.#..#. +#.#.#..#.. +#.#.#..#.. +#.#.#.#... +......#... +##....#... +......#... +.......#.# +..#..###.# +..#######. + +Tile 2441: +#......#.# +..#.##.... +.##....#.# +..#.#..#.. +.#.#...#.# +...#...... +#........# +..#......# +.........# +.#.####.## + +Tile 3877: +.##.#.#... +.#..#.#..# +...#.###.# +......#..# +.#...#.... +##.#...#.# +.##.....## +#........# +##.#...... +#..#.##.#. + +Tile 2437: +#.##...##. +..#....... +#..#..#..# +.......#.. +#.##.....# +.......... +.........# +....#....# +.#......#. +.#..#.##.# + +Tile 3613: +###....... +#.##...... +###.....#. +#.##...... +#.....#... +....#....# +##.......# +#.#..#.... +#..#.....# +#..#.#.#.# + +Tile 3761: +#.##.#.### +#..#.....# +##.#..#.## +##......## +##....#..# +#.#.#..#.. +.........# +#.....#..# +#.#....... +...#####.# + +Tile 3499: +.###.#.### +......#..# +#........# +.......... +#......... +...##..#.# +#....#...# +....#.#... +#...#...#. +#.##.##..# + +Tile 3511: +.........# +.#.......# +.#.....#.. +.......#.. +.#........ +#.#.....## +..#......# +##........ +#........# +.#..#.##.. + +Tile 1543: +###....#.. +...#.##... +#......#.# +.....#.#.. +#.....#..# +#...#.#..# +##....#... +......##.# +......#### +.#.#.#..## + +Tile 2897: +###..##.## +....##.... +#..#...... +.......#.# +.##.#.#..# +#......#.# +.........# +#......... +.....###.. +##...#.... + +Tile 1607: +..###.#.## +#........# +.#.#...#.. +.......... +#........# +###.....#. +.##..##..# +###....... +#..#.#...# +###...##.# + +Tile 3313: +.####.#.#. +.##......# +#......... +....#..... +#..#..#### +#.....#... +#..#..##.. +#.#..##.## +###.#..### +##.....#.. + +Tile 1433: +#.#.#.##.# +#..#....## +#.#......# +#.....#..# +#....#...# +#......... +.........# +...##.##.# +.......... +#...#...#. + +Tile 3947: +.##...##.. +#...#..#.# +.......#.. +#.......#. +.#..#....# +.##......# +####.#..#. +##.##..#.# +#.#..#.... +###...##.. + +Tile 2879: +.#.###.... +##..#..#.# +##...##... +.....#.... +.........# +..#....... +##.......# +.#...#...# +...##..... +##...#.... + +Tile 2129: +##..#..#.# +....#.#.## +.#.......# +#...#...#. +......#..# +#..#....## +........## +.#....###. +#.....#### +.....#.#.. + +Tile 3089: +..####.### +.......... +.....#.#.# +#..###..#. +#.#....... +.....#.... +##.#.#.... +#....##..# +##.......# +#...##.#.. + +Tile 2459: +###.#..#.# +.#.......# +.#........ +#.#..#.... +....##...# +#.#....#.. +#....####. +..###..#.# +.........# +.######### + +Tile 3119: +#..#.##..# +#........# +..#.#....# +#.####...# +###....... +....#....# +........## +.......... +##....#.## +#.#.#.##.. + +Tile 2393: +...#..#..# +....#..... +#......##. +.#.#.#.### +.........# +#......... +#.......## +##.......# +#..##...## +##..#..#.# + +Tile 1193: +.##...###. +#.....##.. +#.....#... +#......... +#...###.## +.#..#..#.# +..#....... +#..#....## +......#..# +#..#.#.### + +Tile 2969: +...#...##. +.........# +..#....### +####...#.# +#........# +#......#.# +#..##....# +#...##.... +#..##..... +.#.#.#.#.# + +Tile 1453: +#..#.#..#. +......#... +##.###.... +#....#...# +...#.#.##. +.....#.... +#......#.. +.##.....## +.#...#...# +.##.#..### + +Tile 2543: +#....#.... +#...#.#... +#.......#. +#........# +....#.##.# +..##...#.. +##.......# +#..#..#... +.........# +#...#..#.. + +Tile 3739: +##.####... +#.#..#.... +.........# +.......#.. +.#....##.. +#.....#... +#..#...... +#........# +#...#..... +#.....#.## + +Tile 2699: +#.#.#.#... +...#.....# +#........# +#..#...#.# +#.#.#.#### +.#..#.##.. +#....##... +##...##..# +.......... +#####.#..# + +Tile 2609: +.#.###.##. +...#....#. +.......... +.###...#.. +........## +#......#.. +.###.##..# +#.#....#.# +#.#.#..... +.#.###..## + +Tile 1949: +#....#.#.. +#.#....... +##.......# +##...#..#. +.....###.# +......#... +.........# +.........# +#.###..#.# +..##.##.#. + +Tile 3697: +####..##.. +#.#......# +#.......## +#.....#... +###.#..#.. +##.####..# +.#.......# +...##..... +#......... +..##.###.# + +Tile 3019: +########.. +.......##. +........## +#....##.#. +.......... +....#....# +#.#......# +##...#.... +#......... +####..#... + +Tile 1277: +..##.##### +#......... +.........# +..#.#....# +##.......# +.......... +##.#.#..#. +#...#....# +##.....#.. +.#.....##. + +Tile 2801: +#####..##. +#...##...# +#......... +..#...##.. +#......... +.##...#... +....##.... +...##..#.. +.##.#.#..# +#.##....## + +Tile 2903: +#######.#. +.##.#....# +#.#....#.# +#..#.....# +...##...## +#..#.....# +.#.##....# +..#..#.... +..#....### +....#....# + +Tile 3929: +..#..#.... +##........ +#..#...... +##..#..... +.........# +.....#.... +..#..#...# +...#...... +#.......## +####.###.. + +Tile 1039: +###.#.#### +#....#...# +..#.###... +#..#..#... +###....### +##.#.#...# +.......... +#...#####. +####.#..#. +##.....#.. + +Tile 2549: +...##.#.#. +#........# +#......... +.......#.# +#...#..... +#.#...#..# +#.....#... +.......#.. +#......... +..#...#### + +Tile 3673: +###...#... +.##..#.... +..#...#.## +.#......## +.........# +#.....#... +##.#..#... +#........# +#........# +.......### + +Tile 3911: +########.# +#......... +####.....# +.........# +#......... +##.##...#. +#......### +......#..# +##.....#.. +..#..#..#. + +Tile 1163: +#..##.#.#. +........## +#...#...## +#....#...# +.......... +..#......# +.....#...# +......#### +......#... +#.#..#.#.# + +Tile 2293: +..#.#..#.. +...###...# +.....#.... +##.......# +#......#.. +#......#.# +#...#....# +#.#.#..... +....#..... +..####.#.# + +Tile 3541: +#..#...##. +..##...#.# +##....##.# +#......#.# +##....#... +.......... +#...#.#... +##.##..#.# +#.##.....# +......###. + +Tile 3767: +#.#..##### +#......#.# +.......#.# +..##..#..# +.........# +#.#.##...# +#...#....# +#.....###. +#........# +#.##.##### + +Tile 2131: +###...#.#. +.#.....#.# +##.......# +#...#...## +#...#...## +...#..#... +#.......## +#..#.....# +.........# +...#...... + +Tile 3923: +###...#.#. +#....#...# +###...#... +#.#.#..... +#..##....# +...#.#..## +.......... +#.#......# +##.#...#.# +#..#.##..# + +Tile 2789: +.....##... +.#.....#.# +.#..#..#.. +....#...## +..#.#..... +.#.#...... +#....#.... +#......... +#.#......# +#.#.###### + +Tile 3607: +####...#.# +..#.#.#.#. +....##.#.. +#........# +.........# +.###....#. +#......... +#......#.. +.#.#..#..# +###.##.##. + +Tile 1187: +..#....### +##........ +.....#..#. +##.#.#.... +#.#....... +..#...#..# +#..#..#... +#.#..#...# +##.......# +###...##.# + +Tile 1933: +.#.##..### +...#.....# +#........# +..#..#.... +#...#..... +.#.#.#.... +###....... +#.....#... +.........# +#...#...## + +Tile 1571: +...#.#.#.# +#.#......# +#....#...# +#.#...#..# +..#....#.. +.........# +.......... +.......... +....#....# +..#..#.#.. + +Tile 1451: +.#.......# +#.......#. +##.....#.. +....#.#..# +##......## +#..#...... +#........# +.#..#...## +##.#..#..# +#.######## + +Tile 1051: +##.#.##... +...#..#..# +..##.#...# +....#....# +##........ +#......... +...#.....# +#......... +..###..... +.##.###### + +Tile 3637: +.#........ +.......... +#...###... +.......... +..#..#...# +##.....#.. +.#...#...# +#...#.#... +...#.##.## +######.#.. + +Tile 3163: +####.##.## +#.....#..# +.........# +##.......# +........#. +........#. +..#....#.. +.....#...# +#......##. +#......... + +Tile 1409: +..##.####. +#....#...# +#.....#..# +##.#.....# +...#.#...# +#..#..#..# +......#..# +.#.###.... +#.#..##..# +.##.###..# + +Tile 1069: +...#..##.. +.........# +.......... +.........# +.#........ +#..#.#.#.# +#........# +........## +.......#.# +####.###.. + +Tile 2339: +.#######.. +...#...#.# +.......#.. +......#... +.#.#.#.... +#.#......# +#.#.#....# +#..##....# +.........# +##..#.###. + +Tile 3343: +.##..#...# +#...#.#..# +..#....... +.......#.# +#.....#... +.#..#.##.. +.#........ +#..#.#.... +#.......## +#.#..#...# + +Tile 1103: +.###.#.### +.........# +#...#.##.# +.......#.# +#.....#... +#......... +#...#..#.. +.......#.# +#..#.#...# +#...###.#. + +Tile 3583: +#.##...#.# +##.#..#..# +....#..... +......##.# +##.....#.# +.#........ +##....#... +.....#...# +#........# +#####..##. + +Tile 1361: +##..#.##.# +......#... +....#....# +##.......# +.....#.... +.#...#.#.. +##.......# +..##...... +#....#.#.. +#.#.#.#### + +Tile 1597: +##.#.#.##. +.#.#.....# +.#...#.#.# +#.#....#.# +.......##. +..#..#.... +...#....## +#.......#. +.#.#...... +##.#..###. + +Tile 2963: +.#.#####.# +##.....##. +#.......#. +#.....#..# +#..#....## +..#......# +.##...#..# +..##.....# +#......... +.##......# + +Tile 2039: +#######... +##........ +#....#.#.# +#.#...#..# +#..#..#... +...#..#..# +####..#### +.#.....#.# +#........# +#..###..#. + +Tile 1181: +#..###...# +...#.#...# +###..#.#.. +..#.#..#.. +......##.. +#.#..#.##. +...#.###.. +.#..#.#..# +.........# +.###.#..## + +Tile 1697: +#.#.#..##. +#.###..... +#...#.#.## +....###... +#...#..... +..##.....# +.....#.... +#........# +...##..... +##.###.### + +Tile 3001: +###...###. +#........# +#...#....# +..#..#.... +#.#...###. +#..#....## +#.#.#....# +#...#....# +....#...#. +.##..#.##. + +Tile 1319: +.#.#####.. +.......#.# +..##....#. +#........# +#.##.....# +#.#...#... +........## +.....#...# +######...# +#.##...... + +Tile 3307: +#..#.#.### +.......... +##.##..... +#.#.#..... +....#..... +.........# +##.....#.# +..#....... +#.....#..# +.###.##..# diff --git a/inputs/20_test b/inputs/20_test new file mode 100644 index 0000000..b07aa4b --- /dev/null +++ b/inputs/20_test @@ -0,0 +1,107 @@ +Tile 2311: +..##.#..#. +##..#..... +#...##..#. +####.#...# +##.##.###. +##...#.### +.#.#.#..## +..#....#.. +###...#.#. +..###..### + +Tile 1951: +#.##...##. +#.####...# +.....#..## +#...###### +.##.#....# +.###.##### +###.##.##. +.###....#. +..#.#..#.# +#...##.#.. + +Tile 1171: +####...##. +#..##.#..# +##.#..#.#. +.###.####. +..###.#### +.##....##. +.#...####. +#.##.####. +####..#... +.....##... + +Tile 1427: +###.##.#.. +.#..#.##.. +.#.##.#..# +#.#.#.##.# +....#...## +...##..##. +...#.##### +.#.####.#. +..#..###.# +..##.#..#. + +Tile 1489: +##.#.#.... +..##...#.. +.##..##... +..#...#... +#####...#. +#..#.#.#.# +...#.#.#.. +##.#...##. +..##.##.## +###.##.#.. + +Tile 2473: +#....####. +#..#.##... +#.##..#... +######.#.# +.#...#.#.# +.######### +.###.#..#. +########.# +##...##.#. +..###.#.#. + +Tile 2971: +..#.#....# +#...###... +#.#.###... +##.##..#.. +.#####..## +.#..####.# +#..#.#..#. +..####.### +..#.#.###. +...#.#.#.# + +Tile 2729: +...#.#.#.# +####.#.... +..#.#..... +....#..#.# +.##..##.#. +.#.####... +####.#.#.. +##.####... +##..#.##.. +#.##...##. + +Tile 3079: +#.#.#####. +.#..###### +..#....... +######.... +####.#..#. +.#...#.##. +#.#####.## +..#.###... +..#....... +..#.###... diff --git a/main.py b/main.py index 8e95e80..b0c25b6 100755 --- a/main.py +++ b/main.py @@ -58,7 +58,11 @@ for lib in sorted(imported): if not flags.part or flags.part == 1: if not flags.timeit: - aoclib.printSolution(day, 1, globals()[lib].part1(test_mode=flags.test), test=flags.test) + solution = globals()[lib].part1(test_mode=flags.test) + if flags.test: + aoclib.printSolution(day, 1, solution, test=globals()[lib].TEST_SOLUTION_PART1) + else: + aoclib.printSolution(day, 1, solution) else: exec_time = timeit.timeit( 'globals()[lib].part1(test_mode=flags.test)', @@ -69,7 +73,11 @@ for lib in sorted(imported): if not flags.part or flags.part == 2: if not flags.timeit: - aoclib.printSolution(day, 2, globals()[lib].part2(test_mode=flags.test), test=flags.test) + solution = globals()[lib].part2(test_mode=flags.test) + if flags.test: + aoclib.printSolution(day, 2, solution, test=globals()[lib].TEST_SOLUTION_PART2) + else: + aoclib.printSolution(day, 2, solution) else: exec_time = timeit.timeit( 'globals()[lib].part2(test_mode=flags.test)',