From 8b2c3bdfa1181d32e8ab863877aa1cc8491e12f6 Mon Sep 17 00:00:00 2001 From: Dmitry Fedotov Date: Mon, 6 Jan 2025 02:13:07 +0300 Subject: [PATCH] add day 16 part 1 --- day16/code.py | 109 ++++++++++++++++++++++++++++++++ day16/input.txt | 141 ++++++++++++++++++++++++++++++++++++++++++ day16/input_test.txt | 15 +++++ day16/input_test2.txt | 17 +++++ day16/task.txt | 84 +++++++++++++++++++++++++ 5 files changed, 366 insertions(+) create mode 100644 day16/code.py create mode 100644 day16/input.txt create mode 100644 day16/input_test.txt create mode 100644 day16/input_test2.txt create mode 100644 day16/task.txt diff --git a/day16/code.py b/day16/code.py new file mode 100644 index 0000000..380733b --- /dev/null +++ b/day16/code.py @@ -0,0 +1,109 @@ +import sys +sys.path.append('../aoclib') + +from aoclib import Input +import heapq +sys.setrecursionlimit(15000) + +L = '<' +U = '^' +R = '>' +D = 'v' + +EMPTY = '.' +WALL = '#' +START = 'S' +END = 'E' + + +class Maze: + def __init__(self, lines: list[list[str]]): + self.grid = lines + for y in range(len(self.grid)): + for x in range(len(self.grid[0])): + if self.grid[y][x] == START: + self.s = (x, y) + elif self.grid[y][x] == END: + self.e = (x, y) + + def __str__(self): + grid = [r.copy() for r in self.grid] + return '\n'.join(''.join(row) for row in grid) + + def start(self) -> tuple[int, int]: + return self.s + + def end(self, pos: tuple[int, int]) -> bool: + return self.e == pos + + def is_wall(self, pos) -> bool: + x, y = pos + return self.grid[y][x] == WALL + + +def search(m: Maze) -> int: + x, y = m.start() + state = (x, y, 1, 0) + + queue = [] + visited = set() + heapq.heappush(queue, (0, state)) + visited.add(state) + + while queue: + cost, state = heapq.heappop(queue) + x, y, xd, yd = state + + if m.end((x, y)): + return cost + + options = [ + # move forward + (cost+1, (x+xd, y+yd, xd, yd)), + # turn + (cost+1000, (x, y, -yd, xd)), + (cost+1000, (x, y, yd, -xd)), + ] + + for opt in options: + cost, state = opt + x, y, _, _ = state + if m.is_wall((x, y)): + continue + if state in visited: + continue + + visited.add(state) + heapq.heappush(queue, (cost, state)) + return -1 + +def solve1(lines: list[list[str]]): + m = Maze(lines) + res = search(m) + return res + + +def solve2(lines: list[list[str]]): + maze = Maze(lines) + return '' + + +if __name__ == '__main__': + lines = Input('input_test.txt').lines_as_lists() + #part 1 + print('test part 1:', solve1(lines)) + #part 2 + print('test part 2:', solve2(lines)) + + lines = Input('input_test2.txt').lines_as_lists() + #part 1 + print('test 2 part 1:', solve1(lines)) + #part 2 + print('test 2 part 2:', solve2(lines)) + + lines = Input('input.txt').lines_as_lists() + #part 1 + print('part 1:', solve1(lines)) # 90460 + + #part 2 + print('part 2:', solve2(lines)) diff --git a/day16/input.txt b/day16/input.txt new file mode 100644 index 0000000..1abfb2e --- /dev/null +++ b/day16/input.txt @@ -0,0 +1,141 @@ +############################################################################################################################################# +#.......#...#.#.........................#.......#...#...........#...#.....#.............#.............#.......#.....#.....#................E# +#.#####.#.#.#.#.#######.#####.###.#.#.#.#.#.###.#.#.#####.###.#.###.#.###.#.#.###.#####.#####.#######.#.#####.#.#.###.#.#.#######.###.#####.# +#.....#...#.#.........................#.#.#.#.#...#.......#.....#...#.#.#...#.....#...#.............#...#...#...#.....#.#...#...#.........#.# +#.###.#####.#######.#####.#.###.#######.#.#.#.#############.#.###.###.#.#####.#######.#######.#####.#.###.#.#####.#####.###.#.#.#.#.#.###.#.# +#.#.#...#.#.........#.....#...#.#.......#.#.#.#...#.....#...#.....#...#.....#...#.......#...#.................#.........#.#...#.#.#...#...#.# +#.#.###.#.###########.#######.#.#.#######.#.#.#.#.#.###.#.###.###.#.###.###.#.#.#.#####.#.#.#.#.#.#.###.#####.#.#.#######.#####.#.###.#####.# +#.#...#.#.........#.....#...#...#...#.......#.#.#.#...#.#.#...#...#.#.....#...#.#.....#...#.#.#.#.#...#.....#.................#...#...#.....# +#.#.###.#######.###.###.#.#.#######.#.###.###.#.#.#.###.#.###.#####.#.#.#.###.#.#.###.#####.#.#.#.###.#####.#.#.#.#.#.###.###.#####.#.#.##### +#.#...#.....#...#...#.#...#.......#.#.#.....#...#.#.#...#...#.....#.......#...#.#...#.....#.....#.#.#.#.....#.#.#.#.#.#...#.#...#.....#.#...# +#.###.#####.#.#.#.###.#####.#.#####.#.#.###.#.###.#.#.#####.#.###.#####.###.#.#.###.#####.#######.#.#.#.#####.#.#.###.#.###.#.###.###.#.###.# +#.#...#.#...#.#.#.........#.#.#.....#.....#.#...#.................................#.#...#.#...#...#.#.#...#.#...#.#...#.#...#.#...#.#.#.#...# +#.#.#.#.#.###.#######.#####.#.#.###########.#########.#.#####.#.#.###.#.#####.#.#.#.#.#.#.###.#.###.#.###.#.#####.#.###.#.#.#.#.###.#.#.#.### +#...#...#...#.........#.....#.#...#...#.....#...................#.............#.#.#.#.#.#...#.#.#...#.....#...........................#.#...# +#.#####.###.#.#########.#####.###.#.#.#.#####.#####.#######.#.#.#######.#####.#.#.#.#.#.###.#.#.###.#######.#######.#.#.#.###.###.#.#.#.###.# +#.....#.#.#.#.#...#...#.#.......#...#.#...........#.#.......#.#...........#.....#.#.#.#.#...#.........#.....#.......#.#.#.#.....#.#.#...#...# +#.###.#.#.#.###.#.#.#.#.#.###########.#########.###.#.#######.###########.#.#####.#.###.#.###.#####.###.###.#.#######.#.#.#.#####.#.#.###.### +#...............#.#.#...#...#.......#.........#.#.....#...#...........#...#.#.....#.#...#...#.#...#.#...#.#...#.......#.#.....#...#...#.....# +#.#.#####.#######.#.#####.###.###.#.#########.###.###.#.#.#.###.#######.###.###.###.#.#####.###.#.###.#.#.#######.###.#.#####.#.#####.#.#.#.# +#.#.....#.....#...#...#...#.....#.#.#.......#.....#...#.#.#.....#.......#...........#...........#.#...#...........#...#.....#.#.#.....#.#...# +#.#####.###.###.#####.#.###.#.###.#.###.###.#######.###.#.#####.#.#######.###.#.#########.#######.#.###.#####.#.###.#######.###.#.#####.#.### +#.#...#...#.#...#.....#...#.#.....#.....#.#...#.....#...#.......#...#...#.#...#...........#...#...#.#...#...#.#.#.........#.....#...#...#...# +#.#.#.###.###.#####.#######.#.###########.###.#.###.#########.#####.###.#.#.#########.###.#.###.###.#####.#.#.#.#.#######.#######.#.#.###.#.# +#...#.#...........#...#.....#.................#...#.........#.....#...#...........#...#...#...#...........#.#.#.#.#.....#.#...#.#.#.#...#...# +#.###.#.###.###.#.#.#.#.#.#############.###.#####.#########.#########.###.#######.###.#.#####.#############.###.###.###.#.#.#.#.#.#.###.#.#.# +#...#.#...#...#.#.#.#.............#...#...#.#...#...#.....#.........#...#.......#...#...#.....#...#...#.....#...#...#...#...#.#...#.#...#.#.# +#.#.#.#.#.###.#.#.#####.#.#######.###.###.###.#.###.#.#######.#####.###.#####.#####.###.#.###.#.#.#.#.#.#####.#.#.###.#######.#.###.#.###.#.# +#...#.#.#.#...#.#.....#...#...#.....#.....#...#...#.#.#.....#.....#...#.....#.#...#...#.#.#...#.#...#...#.........#.#.#.....#.#...#...#.#.#.# +#.#.#.###.#.###.#####.#.###.#.#####.#.#.#.#.###.###.#.#.###.#####.#.#.#####.###.#.#.#.#.#.#####.#####.#.#.###.###.#.#.###.###.#####.#.#.#.#.# +#...#...#...#...#.#...#.#...#...#.#...#.#.#.#...#...#.#...#.........#.#.....#...#.....#...#...#...#...#.#...#...#.#.....#.........#.#...#.#.# +#.#####.#.#####.#.#.#####.#####.#.#.###.###.#.#.#.###.###.#########.###.#####.#########.###.#.###.#.###.###.###.#.#####.#########.#.#.#.#.#.# +#...#...#.....#...#.#.....#.....#.#.#...#...#.....#...#.#.#.........#.......#.....#.....#...#...#.#.#.#...#.#.......#.#.....#...............# +#.#.#.###.###.###.#.#.#####.#.#.#.#.#.###.#########.#.#.#.#.#########.###.#.#.###.#######.#####.#.#.#.###.#.#.#.###.#.#####.#.#.###.#.#.#.#.# +#.#.#...#.....#...#.#.#.....#...#...#...#.........#.#...#.#.#.....#...#...#.....#...#...#.#.......#.#.....#.#.#.....#...#...#.#.#.#.#.#.#.#.# +#.#.###.#.#####.###.#.#.###########.###.#########.#.#.###.#.#.#.###.###.###########.#.#.#.#########.#####.###.#.#####.###.###.#.#.#.#.###.#.# +#...#...............#.#...............#.......#...#.#.#...#...#.........#.........#...#.#.....#.........#.....#...#...#...#...#.#.....#...#.# +#.###.###.#.#.###.###.###########.###########.#.###.#.#.#######.###.#.###.#######.#####.#####.#.#######.#.#######.#.###.###.###.#####.#.##### +#.#.#.#...#...#...#...#.......#...#.....#.....#.....#.#.........#...#.#.#.#.....#...........#.......#...#.#.....#.#.#...#.....#...#...#.....# +#.#.#.#.#.#.###.###.###.#####.#.###.###.#.###########.###########.###.#.#.#####.#####.#########.###.#.#####.###.#.#.#.###.###.###.#.#.###.#.# +#...#.#.#.#.#...#...#...#...#.#.....#...#.#.........#.#.#.....#.#.....#.#.......#.....#...#...#.....#.......#.#...#.#.#.#.#...#.#...#...#.#.# +#####.#.#.#.#.###.###.#####.#.#####.#.###.#.#######.#.#.#.#.#.#.#.#####.###.#.#.#.#####.#.#.#.###.###########.#####.#.#.#.#.#.#.#######.###.# +#.....#.#.#.#.......#.#.....#.#...#.#.#...#.......#.#.#...#.#.#.......#...#.#.#.#.....#.#...#...#.#.....#...........#.#...#.#...............# +#.#####.#.#.#########.#.#.###.#.#.###.###.#.#######.#.#.###.#.#######.#.#.#.#.#######.#.#####.#.#.#.###.###.#####.###.#####.###.###.#.#.#.#.# +#.#...#.#...#.#.......#.#...#.#.#.#...#...#.#...#...#.#...#.#.......#...#.#.#.#.......#...#...#.#.#.#.......#...#.#...#.....#.#...#.#.#.....# +#.#.###.#.###.#.#######.#.#.#.#.#.#.###.###.#.#.#.###.###.#.#######.###.###.#.#.#########.###.#.#.#.###.###.#.#.###.###.#####.###.###.#####.# +#.#.....#.....#...#...#...#.#...#...#...#...#.#.#...........#.....#...#.#...#...#.......#...#.....#...#.....#.#.....#...#.............#...#.# +#.#.#####.#######.#.###.###.#.#######.###.###.#.#############.#######.###.###.###.#####.###.#######.#.#.#####.#########.#.###########.#.#.#.# +#.#...............#...#...#.....#...........#.#...#.....#...#.........#...#.#...#...#.....#...#...#...#...#...#.#.......#.#.....#...#.#.#.#.# +#.#######.#########.#.#.###.#####.###########.#.#.#.###.#.#.#.#########.###.###.#####.#####.#.#.#.#.#.#####.###.#.#.#####.#.###.###.#.#.#.#.# +#.........#.......#.#...#...#.....#...#.....#...#...#...#.#.#.......#...#...#...#.....#.......#.#.#.#.....#...#.#.#.....#.#.#.#...#.....#.#.# +#.###.###.#.#.###.#.###.#.###.#####.#.#.###.###.#####.###.#.#####.#.#.###.###.###.#####.#####.#.###.#####.###.#.#.#####.###.#.###.###.#####.# +#.#...#.........#.#.....#...........#.#.#.......#.....#...#.........#...#.........#.....#...#.......#...#...#.#.#...#...#.......#...#.#.....# +#.#.#.#.#######.#.#.#######.#####.###.#.###########.#########.#.#######.#.#########.#####.###.#########.###.#.#.###.#.###.#######.#.###.##### +#.#.#...#.....#.#.#.#.....#.....#...#.#...........#.........#.............#.........#.#.......#.......#...#...#.....#.#...#.........#...#...# +#.#.#.###.###.#.###.#.###.#####.#####.###########.#####.###.###.#.#########.#########.#.#########.#.#.#.#.#####.#####.#.###.#####.#.#.#####.# +#.#.#...#.#...#.....#.#.#.#...#...#.....#.#...#...#...#...#.......#.......#.#...#.......#.......#.#.#...#.#...#.#.....#.#...#.....#.#.#...#.# +#.#.#.#.#.#.#########.#.#.#.#.###.#.###.#.#.#.#.###.#.###.###.#.###.#####.#.#.#.#.#.#####.#.###.###.#####.###.#.#.#####.#.###.#.#.#.#.#.#.#.# +#.....#...#.............#...#...#...#.....#.#.#.#...#...#...#.#...#.#.......#.#.#...#...#.#...#...#.....#...#...#.....#.#...#.#...#.#...#...# +#####.#########################.#######.###.#.#.#.#####.#.#.#.#####.#####.###.#.#.#####.#.###.###.#####.###.#.#######.#.###.###.#.#.#######.# +#...#.#.......#...#.............#.....#.#...#.#.......#.#.#.......#.....#.#...#.......#...#.#.#...#...#...#.#.#.....#.#.#.#...#.#.#.#.....#.# +#.#.#.#.#.###.###.#.#####.#####.#.###.#.#.###.#########.#####.###.#.###.###.###.#####.###.#.#.###.#.#.###.#.#.#.###.#.#.#.###.###.#.#####.#.# +#.#.#.#.#...#...#.#.#...#.#...#.#.#...#.#.#.......#...#.#...#.#...#...#.......#...#.#...#...#...#.#.#.#...#.#.#.#...#.#.#...#...#...#.....#.# +#.#.#.#####.###.#.#.#.#.#.#.#.###.#.#####.#######.#.#.#.#.#.#.#.#####.###########.#.###.#.#####.#.#.#.#.###.###.#.###.#.#.#####.###.#.#####.# +#.#.#.#.....#.....#...#...#.#...#.#.....#...#...#...#.#...#.#.#.....#...#...#.....#...#.#.#.....#...#...#...#...#.#...#.#.#.......#...#.....# +#.#.#.#.#.#######.#####.#.#.###.#.#####.###.#.#.#.###.#####.#.#####.#.#.###.#.#####.###.###.#############.###.###.#.#.#.#.#.#.###.#.###.##### +#.#.....#.#...#.......#.#.#...#...#...#.....#.#.#.....#...........#...#.....#...#.....#.....#.....#.#.....#...#.#.#.#...#.#.#...#.#.....#...# +#.###.#####.#.#########.#####.#####.#.#######.###.#####.#####.#.#####.#####.#.#.#####.#######.###.#.#.#####.###.#.#.#####.#.###.#.#.###.#.#.# +#.....#.....#...........#.....#.#...#.........#...#.....#...#.#.....#...#.....#.#.....#.........#.#.#.......#.#...#...#...#...#...#...#...#.# +#####.#.#.#############.#.#####.#.#######.###.#.#####.###.###.#####.###.#####.#.#.###.#########.#.#.#########.#.#####.###.#.#.#######.#.#.### +#.......#.#.......#.....#.#.........#...#.#.#.#.#.....#.....#.....#.........#.#.#...#.....#.....#.....#.....#.#.#.....#.....#.......#...#...# +#.#####.#.#.#####.#####.#.#########.#.#.#.#.#.#.#.#.#####.#.#####.#########.###.#.#.#####.#.#########.#.###.#.#.#.#####.###.#####.#####.###.# +#.#...............#...#.#.......#.....#.#.#.#.#.#.#.#...#.#...#...#.....#.......#.#.#...#...#...#...#...#.#.#.#.#.#.....#...#...#.....#.....# +#.###.#.#.#.###.###.#.#########.#######.#.#.#.#.#.#.#.#.###.###.###.#############.#.#.#.#####.#.#.#.#####.#.#.#.#.#.###.#.#####.#####.#.###.# +#.......#.#.#...#...#.........#...#...#.#.#...#.#.#...#...#.#...#...#.......#...#.#.#.#.....#.#...#.......#...#.#.#...#.#.........#.........# +#.#####.#.#.#.#.#.#####.#.#.#####.#.#.#.#.#####.#.#######.#.#.###.#.#.#####.###.#.#.###.###.#.###########.###.#.#.#####.#########.#.###.#.#.# +#.#.....#.#.#.....#.....#.#.....#...#.#.#...........#.....#.......#...#.#...#...#.#...#.....#...#.......#.......#...#...#.............#...#.# +#.#.#######.#.#####.###.#.#####.#.###.#####.#########.###.#############.#.###.#.#.###.#.#######.#.#####.#######.###.#.#.#####.#########.#.#.# +#.#...#.....#.......#.....#.......#...#...#.......#...#...#...#.......#...#...#.#.....#...#.....#.#...#...#...#...#.#.#.#...#.....#.....#.#.# +#####.#.#####.#######.###.#.#.#.#.#.###.#.#######.#.###.###.#.#.#####.#.###.#.#.###.#.###.#.#####.###.###.#.#.###.#.#.###.#.#####.#.###.###.# +#.....#.#.....#...#.....#.#.....#.#.#...#.......#...#.#.....#...#.#...#.#...#...#...#.#...#.#...#...#.#...#.#.....#.#.....#...#...#...#.....# +#.###.#.#.###.###.#.###.#.#####.###.#.#########.#####.#.###.#####.#.#.#.#####.#.#.###.#.###.#.#.###.#.#.###.#.#####.#.#######.#.#####.#.##### +#...#.#.#...#...#...#...#...#...#...#.#...#...#.#.......#...#.....#.#.#.#.....#.#.#...#.......#.#.#.#.#.....#...#...#.......#.#.#...........# +#.#.###.###.#.#.#####.###.###.###.#.#.#.#.#.#.#.#.#######.###.###.#.###.#.#######.#.###########.#.#.#.#######.###.#########.#.#.###.###.#.#.# +#.#...#.#...#.#.#...#.#...#...#...#.#.#.#.#.#.#.#.#.......#.#...#.#...#.#.#.......#...........#...#.#...........#.#...#.....#.#...#.......#.# +#####.#.#.###.#.#.#.#.#.###.#.#.#####.#.#.#.#.#.###.#######.###.#.###.#.#.#.#########.#######.#.###.#######.###.#.#.#.#####.#.###.###.#.###.# +#.....#...#...#...#...#.#.#.#.#.....#.#.#...#.#.....#.........#.#...#.#.#.....#.............#.#.#...#.....#...#.....#.....#.#.#.#.....#.....# +#.#########.#.#########.#.#.#.###.#.#.#####.#.#######.###.#.###.#.###.#.#####.#.#######.#####.###.###.###.###############.###.#.###.###.###.# +#...#.....................#.#.#.....#...#.....#.....#.#...#.#...#.........#...#.#.....#.#.....#...#...#.#.#.......#...#.....#.#...#...#.....# +#.#.#.#######.#####.#######.#.#.###.###.#.###.###.###.#.#.#.#.###.#.#####.#.###.#.#####.#.#.###.#.#.###.#.#.###.#.#.#.#####.#.#.#.###.#.###.# +#.#.#.#...........#.........#.#.#...#...#.#.......#...#.#.#...#.#.#.......#.....#.........#.#...#...#...#...#...#...#.#...#...#.#.#...#.#...# +#.#.#.#.#####.#.#.#.#########.#.#####.###.#######.#.###.#.#####.#.#################.#####.###.#####.#.#.#####.#######.#.#.#######.#.#####.#.# +#.#...#.#.......#.#...#.......#.......#.......#...#.....#.......#.#...............#.#.........#.....#.#.#...#.......#.#.#.......#.......#.#.# +#.#######.###.#######.###.#####.#.#####.#####.#####.#############.#.#####.#######.###.###.#.#####.###.#.#.#.#.###.#.#.#.#.#####.###.###.#.#.# +#.....#...#.........#...#...#...#...#...#...#.......#.....#.......#...#...#...........#...#.......#...#...#...#.#.#.#.#.......#...#.....#.#.# +#####.#.###.#.#####.###.#####.#####.#.###.#.#########.###.#.#.#######.#.###.#######.#######.#######.###########.#.###.#.#####.###.#.#####.#.# +#...#.#...#.#.....#.....#...........#.#...#...#.....#...#...#.#.....#...#...#...#...#.............#.#...........#.....#...#.......#...#...#.# +#.###.###.#.#.###.#####.#.#.#.#######.#######.#.###.###.#####.#.#.#.#.#.#####.#.#.###.#####.#.#####.###.#.#.###.#######.###.###.#####.###.#.# +#.................#...#.#.#.........#.#.....#.....#...#.....#.#...#...#.....#.#.#.#...#...#.#.#.......#.#.#.#.#.#.......#...#.#...#...#.....# +#.#######.#.#.#####.#.#.#.#####.#####.#.###.#######.#.#####.#####.#########.#.#.#.#.#####.#.###.#.###.#.#.#.#.#.#.#####.#.###.###.#.###.#.#.# +#.#.....#.#.#.....#.#...#.....#...#...#...#.........#...#.#.#.....#.......#...#.#.#.#.....#...#.#...#...#...#.#...#.....#...#.#...#.....#...# +#.#.###.###.#.###.#.#######.#.###.#.###.#.#############.#.#.#.#####.#.#.#.#####.#.#.#.###.###.#.#.###########.#####.#######.#.#.#########.#.# +#.#.#.....#.#.#.#...........#...#...#...#...#.....#.....#.#...#...#.#.#.#...#...#.#...#.#...#...#.....#.......#.....#.......#.#.........#...# +#.#.#####.#.#.#.###############.#####.#####.#.#####.#####.###.#.#.###.#.#.#.#.#########.###.#######.#.#.###.###.#####.#.#####.#########.##### +#.#.....#...#.....#.....#.......#.#...#...#.#.#.....#...........#.....#.#.#.#.#.....#.....#...#...#.#.#.#...#...#.......#.............#.#...# +#.#####.###.#####.#.###.#.#######.#.#####.#.#.#.###########.###########.#.#.#.#.#.###.#.#####.#.###.#.#.#####.###.#####.#.#.#########.#.#.#.# +#...#...#...#...#.#...#...#.....#.......#.#.#...#...........#.....#.....#.#...#.#.#...#.#.....#...#.#...#...#.#.#.......#.#.....#...#.#...#.# +#####.#######.#.#####.#######.#.#######.#.#.#.###.###########.#.###.#####.###.#.#.#.###.#.#######.#.#####.#.#.#.###.#.#####.###.#.#.#.#####.# +#...#.........#.........#...#.#...#.......#.#.....#.....#.........#.#.#...#...#.#...#.#...#.......#.....#.#.........#.....#.#...#.#.#.#...#.# +#.#.###############.###.#.#.#.###.#########.#######.###.#.#######.#.#.#.###.###.#####.#########.#######.#.###########.###.#.#.###.###.#.#.#.# +#.#.#.................#...#...#.#...........#.......#.#...#.....#.#.#.#...#...#.....#.........#.....#...#...........#...#...#.............#.# +#.#.#.###.#####################.#############.###.#.#.#####.###.#.#.#.###.###.#####.#######.#.#####.#.#####.#######.#.###.#.#.###.#######.#.# +#.#...#.#.#.....#...#.....#...#.....#.......#.....#...#.....#.#...#.#...#.........#.....#...#.....#.#...........#...#.#...#.#...#.........#.# +#.#.###.#.#.###.#.#.#.#.#.#.#.#.#.#.#.#.###.#####.###.#.#####.###.#.#.#######.#########.#.#######.#.#######.###.#.#####.#######.###.###.###.# +#.#...#...#...#.#.#.#.#.#...#.#...#...#.........#...#.......#.....#.#.#.....#.........#...#.....#.....#...#.#...#.....#.......#.#.......#...# +#.#.###.#####.#.#.#.#.#.#####.###.#############.###.#.#####.#.#####.#.#.#.#########.#######.#.###.###.#.#.###.#######.#######.#.#######.#.### +#.#...#...#...#.#.#...#...#...#...#.....#.....#.#...#.....#.......#.#.#.#.....#.....#.....#.#...#.#...#.#.....#.....#.........#.#...#...#.#.# +#.#.#.#.###.###.#.#######.#.#.#.###.#.#.###.#.#.#.#.###.#.#.#####.#.#.#.#####.#.###.#.###.#.###.#.#.###.#######.#.#.###########.#.#.#####.#.# +#.#.#...#.....#.#.#.....#.#.#.#...#.#.#.#...#.#...#.....#.#.....#.#.#.#...#...#.#...#.#.#...#.#...#...#...#.....#.#.......#.....#.#.......#.# +#.###.#.#.###.#.#.#.#.###.#.#.###.#.#.#.#.#########.###########.###.#.###.#.###.#####.#.###.#.#######.###.#.#####.#######.#.#####.#########.# +#.....#.#.#...#...#.#...#...#...#.#.#.#.#.......#.....#.......#.....#.....#...#...#...#...#...........#.#...#...#.....#.#...#.....#.........# +#.###.#.#.###.#########.#####.###.###.#.#####.#.#.###.#.#####.###.###########.###.#.###.###.#####.###.#.#####.#######.#.###.#.#########.###.# +#.#.#.#.#.#...........#.....#...#.....#...#...#.....#.#.#...#.......#...........#...#.......#.....#.#.....#.#.......#.#.....#...#.........#.# +#.#.#.#.#.#.#########.#.#.#####.#########.#.#######.#.#.#.#.#.#####.#.#########.#####.#####.#.#####.#####.#.#.#.###.#.#########.###.###.#.#.# +#.#.#.#.#...#.......#.#.#...#.....#.....#.#.....#...#.#.#.#...#.#...#.#.#.......#.#...#.......#.....#.#...#...#...#.#.........#...#.#.....#.# +#.#.#.#.#########.#.#.#####.#.#####.###.#.#.###.#.###.#.#.#####.#.###.#.#.#######.#.###.###.###.###.#.#.###.#.###.#.#########.###.#.###.#.#.# +#.#.#.#...........#.#.......#.....#...#...#...#...#.#...#.....#...#...#.#.....#.......#.....#...#...#.#...#...#.....#.......#.#...#.....#.#.# +#.#.#.#######.#.#.#.#######.#.###.###.#######.#####.#######.#.#.###.###.#####.#.###.#.#####.###.#.###.###.#####.#.#.#.###.#.#.#.#######.#.#.# +#...#...#...#...#.#.....#.#.#.#...#.#...#...#.#.......#...#.#.#.....#.......#...............#...#.......#.....#.#...#.#...#.#...#.......#...# +#.#.#.#.#.#######.###.#.#.#.#.#.#.#.###.#.#.#.#.#####.#.#.#.#.#######.#####.#.#.#.#.#.#.#####.#####.#########.#.#.#####.###.#####.#####.###.# +#.......#...#...#.....#...#...#.#.....#...#.#...#...#...#...#.#.....#...............#...#.........#.#.......#...#.......#.#...#...........#.# +#####.###.#.#.#.#.###.#######.#.#.###.#####.#####.#.#########.#.###.#.#.#.#.#.#.#.#.#.###.#######.###.###.#.#############.###.#.#######.#.#.# +#.....#...#.#.#.......#.......#.....#...#.#.#...#.#.....#.....#.#...#.#.#.#.#...#.#...#...#.....#...#...#.#.....#...#...#.....#.#.......#.#.# +#.###.#####.#.###.#####.#########.#.###.#.#.#.#.#.#####.#.#####.#####.#.###.###.#.#####.###.#####.#.#.###.#.###.###.#.#.#.#####.#.#####.#.#.# +#.#.......#.#...#.......#.....#...#.#...#.#...#...#.....#...#...#.....#...#.#.....#...#.#.#.......#...#...#.....#...#.#.#.....#...#.....#.#.# +#.#.#####.#.#.###.#########.#.#.#.#.#.###.#########.#######.#.###.#####.#.#.#.#.#.#.#.#.#.#.#####.#.###.###.#####.###.#.#####.#####.###.#.#.# +#...#...#.#...#...#.......................#...#...#.......#.#.....#.......#...#.....#.#.#.......#...#...#.........#...#.#.....#.........#...# +#.#####.#.###.#.#.#.#.###.###.#.#.#.#####.#.#.#.#.#.#####.#.#.#####.#####.#####.#####.#.#.#######.#.#.#####.#####.#.###.#.#####.#####.#.#.### +#.#...#.#...#.#.....#...................................#...#...#...#.........#...#.#...#.#.....#...#.#.........#.#.#.#.#.....#.#...#...#...# +#.#.#.#.###.#####.#.###.###.#.#.#.###.#.###.#.#.###.#.#########.#####.#######.#.#.#.#######.###.#.#.#.#.###.###.###.#.#.#####.###.#.#.#.###.# +#S..#.....#.............#.......#.....#.....#.......#.................#.........#...........#.....#.#.........#.......#...........#...#.....# +############################################################################################################################################# diff --git a/day16/input_test.txt b/day16/input_test.txt new file mode 100644 index 0000000..2c21676 --- /dev/null +++ b/day16/input_test.txt @@ -0,0 +1,15 @@ +############### +#.......#....E# +#.#.###.#.###.# +#.....#.#...#.# +#.###.#####.#.# +#.#.#.......#.# +#.#.#####.###.# +#...........#.# +###.#.#####.#.# +#...#.....#.#.# +#.#.#.###.#.#.# +#.....#...#.#.# +#.###.#.#.#.#.# +#S..#.....#...# +############### diff --git a/day16/input_test2.txt b/day16/input_test2.txt new file mode 100644 index 0000000..bc61c57 --- /dev/null +++ b/day16/input_test2.txt @@ -0,0 +1,17 @@ +################# +#...#...#...#..E# +#.#.#.#.#.#.#.#.# +#.#.#.#...#...#.# +#.#.#.#.###.#.#.# +#...#.#.#.....#.# +#.#.#.#.#.#####.# +#.#...#.#.#.....# +#.#.#####.#.###.# +#.#.#.......#...# +#.#.###.#####.### +#.#.#...#.....#.# +#.#.#.#####.###.# +#.#.#.........#.# +#.#.#.#########.# +#S#.............# +################# diff --git a/day16/task.txt b/day16/task.txt new file mode 100644 index 0000000..238fc10 --- /dev/null +++ b/day16/task.txt @@ -0,0 +1,84 @@ +--- Day 16: Reindeer Maze --- +It's time again for the Reindeer Olympics! This year, the big event is the Reindeer Maze, where the Reindeer compete for the lowest score. + +You and The Historians arrive to search for the Chief right as the event is about to start. It wouldn't hurt to watch a little, right? + +The Reindeer start on the Start Tile (marked S) facing East and need to reach the End Tile (marked E). They can move forward one tile at a time (increasing their score by 1 point), but never into a wall (#). They can also rotate clockwise or counterclockwise 90 degrees at a time (increasing their score by 1000 points). + +To figure out the best place to sit, you start by grabbing a map (your puzzle input) from a nearby kiosk. For example: + +############### +#.......#....E# +#.#.###.#.###.# +#.....#.#...#.# +#.###.#####.#.# +#.#.#.......#.# +#.#.#####.###.# +#...........#.# +###.#.#####.#.# +#...#.....#.#.# +#.#.#.###.#.#.# +#.....#...#.#.# +#.###.#.#.#.#.# +#S..#.....#...# +############### +There are many paths through this maze, but taking any of the best paths would incur a score of only 7036. This can be achieved by taking a total of 36 steps forward and turning 90 degrees a total of 7 times: + + +############### +#.......#....E# +#.#.###.#.###^# +#.....#.#...#^# +#.###.#####.#^# +#.#.#.......#^# +#.#.#####.###^# +#..>>>>>>>>v#^# +###^#.#####v#^# +#>>^#.....#v#^# +#^#.#.###.#v#^# +#^....#...#v#^# +#^###.#.#.#v#^# +#S..#.....#>>^# +############### +Here's a second example: + +################# +#...#...#...#..E# +#.#.#.#.#.#.#.#.# +#.#.#.#...#...#.# +#.#.#.#.###.#.#.# +#...#.#.#.....#.# +#.#.#.#.#.#####.# +#.#...#.#.#.....# +#.#.#####.#.###.# +#.#.#.......#...# +#.#.###.#####.### +#.#.#...#.....#.# +#.#.#.#####.###.# +#.#.#.........#.# +#.#.#.#########.# +#S#.............# +################# +In this maze, the best paths cost 11048 points; following one such path would look like this: + +################# +#...#...#...#..E# +#.#.#.#.#.#.#.#^# +#.#.#.#...#...#^# +#.#.#.#.###.#.#^# +#>>v#.#.#.....#^# +#^#v#.#.#.#####^# +#^#v..#.#.#>>>>^# +#^#v#####.#^###.# +#^#v#..>>>>^#...# +#^#v###^#####.### +#^#v#>>^#.....#.# +#^#v#^#####.###.# +#^#v#^........#.# +#^#v#^#########.# +#S#>>^..........# +################# +Note that the path shown above includes one 90 degree turn as the very first move, rotating the Reindeer from facing East to facing North. + +Analyze your map carefully. What is the lowest score a Reindeer could possibly get? +