add day 16 part 1
This commit is contained in:
109
day16/code.py
Normal file
109
day16/code.py
Normal file
@@ -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))
|
141
day16/input.txt
Normal file
141
day16/input.txt
Normal file
@@ -0,0 +1,141 @@
|
||||
#############################################################################################################################################
|
||||
#.......#...#.#.........................#.......#...#...........#...#.....#.............#.............#.......#.....#.....#................E#
|
||||
#.#####.#.#.#.#.#######.#####.###.#.#.#.#.#.###.#.#.#####.###.#.###.#.###.#.#.###.#####.#####.#######.#.#####.#.#.###.#.#.#######.###.#####.#
|
||||
#.....#...#.#.........................#.#.#.#.#...#.......#.....#...#.#.#...#.....#...#.............#...#...#...#.....#.#...#...#.........#.#
|
||||
#.###.#####.#######.#####.#.###.#######.#.#.#.#############.#.###.###.#.#####.#######.#######.#####.#.###.#.#####.#####.###.#.#.#.#.#.###.#.#
|
||||
#.#.#...#.#.........#.....#...#.#.......#.#.#.#...#.....#...#.....#...#.....#...#.......#...#.................#.........#.#...#.#.#...#...#.#
|
||||
#.#.###.#.###########.#######.#.#.#######.#.#.#.#.#.###.#.###.###.#.###.###.#.#.#.#####.#.#.#.#.#.#.###.#####.#.#.#######.#####.#.###.#####.#
|
||||
#.#...#.#.........#.....#...#...#...#.......#.#.#.#...#.#.#...#...#.#.....#...#.#.....#...#.#.#.#.#...#.....#.................#...#...#.....#
|
||||
#.#.###.#######.###.###.#.#.#######.#.###.###.#.#.#.###.#.###.#####.#.#.#.###.#.#.###.#####.#.#.#.###.#####.#.#.#.#.#.###.###.#####.#.#.#####
|
||||
#.#...#.....#...#...#.#...#.......#.#.#.....#...#.#.#...#...#.....#.......#...#.#...#.....#.....#.#.#.#.....#.#.#.#.#.#...#.#...#.....#.#...#
|
||||
#.###.#####.#.#.#.###.#####.#.#####.#.#.###.#.###.#.#.#####.#.###.#####.###.#.#.###.#####.#######.#.#.#.#####.#.#.###.#.###.#.###.###.#.###.#
|
||||
#.#...#.#...#.#.#.........#.#.#.....#.....#.#...#.................................#.#...#.#...#...#.#.#...#.#...#.#...#.#...#.#...#.#.#.#...#
|
||||
#.#.#.#.#.###.#######.#####.#.#.###########.#########.#.#####.#.#.###.#.#####.#.#.#.#.#.#.###.#.###.#.###.#.#####.#.###.#.#.#.#.###.#.#.#.###
|
||||
#...#...#...#.........#.....#.#...#...#.....#...................#.............#.#.#.#.#.#...#.#.#...#.....#...........................#.#...#
|
||||
#.#####.###.#.#########.#####.###.#.#.#.#####.#####.#######.#.#.#######.#####.#.#.#.#.#.###.#.#.###.#######.#######.#.#.#.###.###.#.#.#.###.#
|
||||
#.....#.#.#.#.#...#...#.#.......#...#.#...........#.#.......#.#...........#.....#.#.#.#.#...#.........#.....#.......#.#.#.#.....#.#.#...#...#
|
||||
#.###.#.#.#.###.#.#.#.#.#.###########.#########.###.#.#######.###########.#.#####.#.###.#.###.#####.###.###.#.#######.#.#.#.#####.#.#.###.###
|
||||
#...............#.#.#...#...#.......#.........#.#.....#...#...........#...#.#.....#.#...#...#.#...#.#...#.#...#.......#.#.....#...#...#.....#
|
||||
#.#.#####.#######.#.#####.###.###.#.#########.###.###.#.#.#.###.#######.###.###.###.#.#####.###.#.###.#.#.#######.###.#.#####.#.#####.#.#.#.#
|
||||
#.#.....#.....#...#...#...#.....#.#.#.......#.....#...#.#.#.....#.......#...........#...........#.#...#...........#...#.....#.#.#.....#.#...#
|
||||
#.#####.###.###.#####.#.###.#.###.#.###.###.#######.###.#.#####.#.#######.###.#.#########.#######.#.###.#####.#.###.#######.###.#.#####.#.###
|
||||
#.#...#...#.#...#.....#...#.#.....#.....#.#...#.....#...#.......#...#...#.#...#...........#...#...#.#...#...#.#.#.........#.....#...#...#...#
|
||||
#.#.#.###.###.#####.#######.#.###########.###.#.###.#########.#####.###.#.#.#########.###.#.###.###.#####.#.#.#.#.#######.#######.#.#.###.#.#
|
||||
#...#.#...........#...#.....#.................#...#.........#.....#...#...........#...#...#...#...........#.#.#.#.#.....#.#...#.#.#.#...#...#
|
||||
#.###.#.###.###.#.#.#.#.#.#############.###.#####.#########.#########.###.#######.###.#.#####.#############.###.###.###.#.#.#.#.#.#.###.#.#.#
|
||||
#...#.#...#...#.#.#.#.............#...#...#.#...#...#.....#.........#...#.......#...#...#.....#...#...#.....#...#...#...#...#.#...#.#...#.#.#
|
||||
#.#.#.#.#.###.#.#.#####.#.#######.###.###.###.#.###.#.#######.#####.###.#####.#####.###.#.###.#.#.#.#.#.#####.#.#.###.#######.#.###.#.###.#.#
|
||||
#...#.#.#.#...#.#.....#...#...#.....#.....#...#...#.#.#.....#.....#...#.....#.#...#...#.#.#...#.#...#...#.........#.#.#.....#.#...#...#.#.#.#
|
||||
#.#.#.###.#.###.#####.#.###.#.#####.#.#.#.#.###.###.#.#.###.#####.#.#.#####.###.#.#.#.#.#.#####.#####.#.#.###.###.#.#.###.###.#####.#.#.#.#.#
|
||||
#...#...#...#...#.#...#.#...#...#.#...#.#.#.#...#...#.#...#.........#.#.....#...#.....#...#...#...#...#.#...#...#.#.....#.........#.#...#.#.#
|
||||
#.#####.#.#####.#.#.#####.#####.#.#.###.###.#.#.#.###.###.#########.###.#####.#########.###.#.###.#.###.###.###.#.#####.#########.#.#.#.#.#.#
|
||||
#...#...#.....#...#.#.....#.....#.#.#...#...#.....#...#.#.#.........#.......#.....#.....#...#...#.#.#.#...#.#.......#.#.....#...............#
|
||||
#.#.#.###.###.###.#.#.#####.#.#.#.#.#.###.#########.#.#.#.#.#########.###.#.#.###.#######.#####.#.#.#.###.#.#.#.###.#.#####.#.#.###.#.#.#.#.#
|
||||
#.#.#...#.....#...#.#.#.....#...#...#...#.........#.#...#.#.#.....#...#...#.....#...#...#.#.......#.#.....#.#.#.....#...#...#.#.#.#.#.#.#.#.#
|
||||
#.#.###.#.#####.###.#.#.###########.###.#########.#.#.###.#.#.#.###.###.###########.#.#.#.#########.#####.###.#.#####.###.###.#.#.#.#.###.#.#
|
||||
#...#...............#.#...............#.......#...#.#.#...#...#.........#.........#...#.#.....#.........#.....#...#...#...#...#.#.....#...#.#
|
||||
#.###.###.#.#.###.###.###########.###########.#.###.#.#.#######.###.#.###.#######.#####.#####.#.#######.#.#######.#.###.###.###.#####.#.#####
|
||||
#.#.#.#...#...#...#...#.......#...#.....#.....#.....#.#.........#...#.#.#.#.....#...........#.......#...#.#.....#.#.#...#.....#...#...#.....#
|
||||
#.#.#.#.#.#.###.###.###.#####.#.###.###.#.###########.###########.###.#.#.#####.#####.#########.###.#.#####.###.#.#.#.###.###.###.#.#.###.#.#
|
||||
#...#.#.#.#.#...#...#...#...#.#.....#...#.#.........#.#.#.....#.#.....#.#.......#.....#...#...#.....#.......#.#...#.#.#.#.#...#.#...#...#.#.#
|
||||
#####.#.#.#.#.###.###.#####.#.#####.#.###.#.#######.#.#.#.#.#.#.#.#####.###.#.#.#.#####.#.#.#.###.###########.#####.#.#.#.#.#.#.#######.###.#
|
||||
#.....#.#.#.#.......#.#.....#.#...#.#.#...#.......#.#.#...#.#.#.......#...#.#.#.#.....#.#...#...#.#.....#...........#.#...#.#...............#
|
||||
#.#####.#.#.#########.#.#.###.#.#.###.###.#.#######.#.#.###.#.#######.#.#.#.#.#######.#.#####.#.#.#.###.###.#####.###.#####.###.###.#.#.#.#.#
|
||||
#.#...#.#...#.#.......#.#...#.#.#.#...#...#.#...#...#.#...#.#.......#...#.#.#.#.......#...#...#.#.#.#.......#...#.#...#.....#.#...#.#.#.....#
|
||||
#.#.###.#.###.#.#######.#.#.#.#.#.#.###.###.#.#.#.###.###.#.#######.###.###.#.#.#########.###.#.#.#.###.###.#.#.###.###.#####.###.###.#####.#
|
||||
#.#.....#.....#...#...#...#.#...#...#...#...#.#.#...........#.....#...#.#...#...#.......#...#.....#...#.....#.#.....#...#.............#...#.#
|
||||
#.#.#####.#######.#.###.###.#.#######.###.###.#.#############.#######.###.###.###.#####.###.#######.#.#.#####.#########.#.###########.#.#.#.#
|
||||
#.#...............#...#...#.....#...........#.#...#.....#...#.........#...#.#...#...#.....#...#...#...#...#...#.#.......#.#.....#...#.#.#.#.#
|
||||
#.#######.#########.#.#.###.#####.###########.#.#.#.###.#.#.#.#########.###.###.#####.#####.#.#.#.#.#.#####.###.#.#.#####.#.###.###.#.#.#.#.#
|
||||
#.........#.......#.#...#...#.....#...#.....#...#...#...#.#.#.......#...#...#...#.....#.......#.#.#.#.....#...#.#.#.....#.#.#.#...#.....#.#.#
|
||||
#.###.###.#.#.###.#.###.#.###.#####.#.#.###.###.#####.###.#.#####.#.#.###.###.###.#####.#####.#.###.#####.###.#.#.#####.###.#.###.###.#####.#
|
||||
#.#...#.........#.#.....#...........#.#.#.......#.....#...#.........#...#.........#.....#...#.......#...#...#.#.#...#...#.......#...#.#.....#
|
||||
#.#.#.#.#######.#.#.#######.#####.###.#.###########.#########.#.#######.#.#########.#####.###.#########.###.#.#.###.#.###.#######.#.###.#####
|
||||
#.#.#...#.....#.#.#.#.....#.....#...#.#...........#.........#.............#.........#.#.......#.......#...#...#.....#.#...#.........#...#...#
|
||||
#.#.#.###.###.#.###.#.###.#####.#####.###########.#####.###.###.#.#########.#########.#.#########.#.#.#.#.#####.#####.#.###.#####.#.#.#####.#
|
||||
#.#.#...#.#...#.....#.#.#.#...#...#.....#.#...#...#...#...#.......#.......#.#...#.......#.......#.#.#...#.#...#.#.....#.#...#.....#.#.#...#.#
|
||||
#.#.#.#.#.#.#########.#.#.#.#.###.#.###.#.#.#.#.###.#.###.###.#.###.#####.#.#.#.#.#.#####.#.###.###.#####.###.#.#.#####.#.###.#.#.#.#.#.#.#.#
|
||||
#.....#...#.............#...#...#...#.....#.#.#.#...#...#...#.#...#.#.......#.#.#...#...#.#...#...#.....#...#...#.....#.#...#.#...#.#...#...#
|
||||
#####.#########################.#######.###.#.#.#.#####.#.#.#.#####.#####.###.#.#.#####.#.###.###.#####.###.#.#######.#.###.###.#.#.#######.#
|
||||
#...#.#.......#...#.............#.....#.#...#.#.......#.#.#.......#.....#.#...#.......#...#.#.#...#...#...#.#.#.....#.#.#.#...#.#.#.#.....#.#
|
||||
#.#.#.#.#.###.###.#.#####.#####.#.###.#.#.###.#########.#####.###.#.###.###.###.#####.###.#.#.###.#.#.###.#.#.#.###.#.#.#.###.###.#.#####.#.#
|
||||
#.#.#.#.#...#...#.#.#...#.#...#.#.#...#.#.#.......#...#.#...#.#...#...#.......#...#.#...#...#...#.#.#.#...#.#.#.#...#.#.#...#...#...#.....#.#
|
||||
#.#.#.#####.###.#.#.#.#.#.#.#.###.#.#####.#######.#.#.#.#.#.#.#.#####.###########.#.###.#.#####.#.#.#.#.###.###.#.###.#.#.#####.###.#.#####.#
|
||||
#.#.#.#.....#.....#...#...#.#...#.#.....#...#...#...#.#...#.#.#.....#...#...#.....#...#.#.#.....#...#...#...#...#.#...#.#.#.......#...#.....#
|
||||
#.#.#.#.#.#######.#####.#.#.###.#.#####.###.#.#.#.###.#####.#.#####.#.#.###.#.#####.###.###.#############.###.###.#.#.#.#.#.#.###.#.###.#####
|
||||
#.#.....#.#...#.......#.#.#...#...#...#.....#.#.#.....#...........#...#.....#...#.....#.....#.....#.#.....#...#.#.#.#...#.#.#...#.#.....#...#
|
||||
#.###.#####.#.#########.#####.#####.#.#######.###.#####.#####.#.#####.#####.#.#.#####.#######.###.#.#.#####.###.#.#.#####.#.###.#.#.###.#.#.#
|
||||
#.....#.....#...........#.....#.#...#.........#...#.....#...#.#.....#...#.....#.#.....#.........#.#.#.......#.#...#...#...#...#...#...#...#.#
|
||||
#####.#.#.#############.#.#####.#.#######.###.#.#####.###.###.#####.###.#####.#.#.###.#########.#.#.#########.#.#####.###.#.#.#######.#.#.###
|
||||
#.......#.#.......#.....#.#.........#...#.#.#.#.#.....#.....#.....#.........#.#.#...#.....#.....#.....#.....#.#.#.....#.....#.......#...#...#
|
||||
#.#####.#.#.#####.#####.#.#########.#.#.#.#.#.#.#.#.#####.#.#####.#########.###.#.#.#####.#.#########.#.###.#.#.#.#####.###.#####.#####.###.#
|
||||
#.#...............#...#.#.......#.....#.#.#.#.#.#.#.#...#.#...#...#.....#.......#.#.#...#...#...#...#...#.#.#.#.#.#.....#...#...#.....#.....#
|
||||
#.###.#.#.#.###.###.#.#########.#######.#.#.#.#.#.#.#.#.###.###.###.#############.#.#.#.#####.#.#.#.#####.#.#.#.#.#.###.#.#####.#####.#.###.#
|
||||
#.......#.#.#...#...#.........#...#...#.#.#...#.#.#...#...#.#...#...#.......#...#.#.#.#.....#.#...#.......#...#.#.#...#.#.........#.........#
|
||||
#.#####.#.#.#.#.#.#####.#.#.#####.#.#.#.#.#####.#.#######.#.#.###.#.#.#####.###.#.#.###.###.#.###########.###.#.#.#####.#########.#.###.#.#.#
|
||||
#.#.....#.#.#.....#.....#.#.....#...#.#.#...........#.....#.......#...#.#...#...#.#...#.....#...#.......#.......#...#...#.............#...#.#
|
||||
#.#.#######.#.#####.###.#.#####.#.###.#####.#########.###.#############.#.###.#.#.###.#.#######.#.#####.#######.###.#.#.#####.#########.#.#.#
|
||||
#.#...#.....#.......#.....#.......#...#...#.......#...#...#...#.......#...#...#.#.....#...#.....#.#...#...#...#...#.#.#.#...#.....#.....#.#.#
|
||||
#####.#.#####.#######.###.#.#.#.#.#.###.#.#######.#.###.###.#.#.#####.#.###.#.#.###.#.###.#.#####.###.###.#.#.###.#.#.###.#.#####.#.###.###.#
|
||||
#.....#.#.....#...#.....#.#.....#.#.#...#.......#...#.#.....#...#.#...#.#...#...#...#.#...#.#...#...#.#...#.#.....#.#.....#...#...#...#.....#
|
||||
#.###.#.#.###.###.#.###.#.#####.###.#.#########.#####.#.###.#####.#.#.#.#####.#.#.###.#.###.#.#.###.#.#.###.#.#####.#.#######.#.#####.#.#####
|
||||
#...#.#.#...#...#...#...#...#...#...#.#...#...#.#.......#...#.....#.#.#.#.....#.#.#...#.......#.#.#.#.#.....#...#...#.......#.#.#...........#
|
||||
#.#.###.###.#.#.#####.###.###.###.#.#.#.#.#.#.#.#.#######.###.###.#.###.#.#######.#.###########.#.#.#.#######.###.#########.#.#.###.###.#.#.#
|
||||
#.#...#.#...#.#.#...#.#...#...#...#.#.#.#.#.#.#.#.#.......#.#...#.#...#.#.#.......#...........#...#.#...........#.#...#.....#.#...#.......#.#
|
||||
#####.#.#.###.#.#.#.#.#.###.#.#.#####.#.#.#.#.#.###.#######.###.#.###.#.#.#.#########.#######.#.###.#######.###.#.#.#.#####.#.###.###.#.###.#
|
||||
#.....#...#...#...#...#.#.#.#.#.....#.#.#...#.#.....#.........#.#...#.#.#.....#.............#.#.#...#.....#...#.....#.....#.#.#.#.....#.....#
|
||||
#.#########.#.#########.#.#.#.###.#.#.#####.#.#######.###.#.###.#.###.#.#####.#.#######.#####.###.###.###.###############.###.#.###.###.###.#
|
||||
#...#.....................#.#.#.....#...#.....#.....#.#...#.#...#.........#...#.#.....#.#.....#...#...#.#.#.......#...#.....#.#...#...#.....#
|
||||
#.#.#.#######.#####.#######.#.#.###.###.#.###.###.###.#.#.#.#.###.#.#####.#.###.#.#####.#.#.###.#.#.###.#.#.###.#.#.#.#####.#.#.#.###.#.###.#
|
||||
#.#.#.#...........#.........#.#.#...#...#.#.......#...#.#.#...#.#.#.......#.....#.........#.#...#...#...#...#...#...#.#...#...#.#.#...#.#...#
|
||||
#.#.#.#.#####.#.#.#.#########.#.#####.###.#######.#.###.#.#####.#.#################.#####.###.#####.#.#.#####.#######.#.#.#######.#.#####.#.#
|
||||
#.#...#.#.......#.#...#.......#.......#.......#...#.....#.......#.#...............#.#.........#.....#.#.#...#.......#.#.#.......#.......#.#.#
|
||||
#.#######.###.#######.###.#####.#.#####.#####.#####.#############.#.#####.#######.###.###.#.#####.###.#.#.#.#.###.#.#.#.#.#####.###.###.#.#.#
|
||||
#.....#...#.........#...#...#...#...#...#...#.......#.....#.......#...#...#...........#...#.......#...#...#...#.#.#.#.#.......#...#.....#.#.#
|
||||
#####.#.###.#.#####.###.#####.#####.#.###.#.#########.###.#.#.#######.#.###.#######.#######.#######.###########.#.###.#.#####.###.#.#####.#.#
|
||||
#...#.#...#.#.....#.....#...........#.#...#...#.....#...#...#.#.....#...#...#...#...#.............#.#...........#.....#...#.......#...#...#.#
|
||||
#.###.###.#.#.###.#####.#.#.#.#######.#######.#.###.###.#####.#.#.#.#.#.#####.#.#.###.#####.#.#####.###.#.#.###.#######.###.###.#####.###.#.#
|
||||
#.................#...#.#.#.........#.#.....#.....#...#.....#.#...#...#.....#.#.#.#...#...#.#.#.......#.#.#.#.#.#.......#...#.#...#...#.....#
|
||||
#.#######.#.#.#####.#.#.#.#####.#####.#.###.#######.#.#####.#####.#########.#.#.#.#.#####.#.###.#.###.#.#.#.#.#.#.#####.#.###.###.#.###.#.#.#
|
||||
#.#.....#.#.#.....#.#...#.....#...#...#...#.........#...#.#.#.....#.......#...#.#.#.#.....#...#.#...#...#...#.#...#.....#...#.#...#.....#...#
|
||||
#.#.###.###.#.###.#.#######.#.###.#.###.#.#############.#.#.#.#####.#.#.#.#####.#.#.#.###.###.#.#.###########.#####.#######.#.#.#########.#.#
|
||||
#.#.#.....#.#.#.#...........#...#...#...#...#.....#.....#.#...#...#.#.#.#...#...#.#...#.#...#...#.....#.......#.....#.......#.#.........#...#
|
||||
#.#.#####.#.#.#.###############.#####.#####.#.#####.#####.###.#.#.###.#.#.#.#.#########.###.#######.#.#.###.###.#####.#.#####.#########.#####
|
||||
#.#.....#...#.....#.....#.......#.#...#...#.#.#.....#...........#.....#.#.#.#.#.....#.....#...#...#.#.#.#...#...#.......#.............#.#...#
|
||||
#.#####.###.#####.#.###.#.#######.#.#####.#.#.#.###########.###########.#.#.#.#.#.###.#.#####.#.###.#.#.#####.###.#####.#.#.#########.#.#.#.#
|
||||
#...#...#...#...#.#...#...#.....#.......#.#.#...#...........#.....#.....#.#...#.#.#...#.#.....#...#.#...#...#.#.#.......#.#.....#...#.#...#.#
|
||||
#####.#######.#.#####.#######.#.#######.#.#.#.###.###########.#.###.#####.###.#.#.#.###.#.#######.#.#####.#.#.#.###.#.#####.###.#.#.#.#####.#
|
||||
#...#.........#.........#...#.#...#.......#.#.....#.....#.........#.#.#...#...#.#...#.#...#.......#.....#.#.........#.....#.#...#.#.#.#...#.#
|
||||
#.#.###############.###.#.#.#.###.#########.#######.###.#.#######.#.#.#.###.###.#####.#########.#######.#.###########.###.#.#.###.###.#.#.#.#
|
||||
#.#.#.................#...#...#.#...........#.......#.#...#.....#.#.#.#...#...#.....#.........#.....#...#...........#...#...#.............#.#
|
||||
#.#.#.###.#####################.#############.###.#.#.#####.###.#.#.#.###.###.#####.#######.#.#####.#.#####.#######.#.###.#.#.###.#######.#.#
|
||||
#.#...#.#.#.....#...#.....#...#.....#.......#.....#...#.....#.#...#.#...#.........#.....#...#.....#.#...........#...#.#...#.#...#.........#.#
|
||||
#.#.###.#.#.###.#.#.#.#.#.#.#.#.#.#.#.#.###.#####.###.#.#####.###.#.#.#######.#########.#.#######.#.#######.###.#.#####.#######.###.###.###.#
|
||||
#.#...#...#...#.#.#.#.#.#...#.#...#...#.........#...#.......#.....#.#.#.....#.........#...#.....#.....#...#.#...#.....#.......#.#.......#...#
|
||||
#.#.###.#####.#.#.#.#.#.#####.###.#############.###.#.#####.#.#####.#.#.#.#########.#######.#.###.###.#.#.###.#######.#######.#.#######.#.###
|
||||
#.#...#...#...#.#.#...#...#...#...#.....#.....#.#...#.....#.......#.#.#.#.....#.....#.....#.#...#.#...#.#.....#.....#.........#.#...#...#.#.#
|
||||
#.#.#.#.###.###.#.#######.#.#.#.###.#.#.###.#.#.#.#.###.#.#.#####.#.#.#.#####.#.###.#.###.#.###.#.#.###.#######.#.#.###########.#.#.#####.#.#
|
||||
#.#.#...#.....#.#.#.....#.#.#.#...#.#.#.#...#.#...#.....#.#.....#.#.#.#...#...#.#...#.#.#...#.#...#...#...#.....#.#.......#.....#.#.......#.#
|
||||
#.###.#.#.###.#.#.#.#.###.#.#.###.#.#.#.#.#########.###########.###.#.###.#.###.#####.#.###.#.#######.###.#.#####.#######.#.#####.#########.#
|
||||
#.....#.#.#...#...#.#...#...#...#.#.#.#.#.......#.....#.......#.....#.....#...#...#...#...#...........#.#...#...#.....#.#...#.....#.........#
|
||||
#.###.#.#.###.#########.#####.###.###.#.#####.#.#.###.#.#####.###.###########.###.#.###.###.#####.###.#.#####.#######.#.###.#.#########.###.#
|
||||
#.#.#.#.#.#...........#.....#...#.....#...#...#.....#.#.#...#.......#...........#...#.......#.....#.#.....#.#.......#.#.....#...#.........#.#
|
||||
#.#.#.#.#.#.#########.#.#.#####.#########.#.#######.#.#.#.#.#.#####.#.#########.#####.#####.#.#####.#####.#.#.#.###.#.#########.###.###.#.#.#
|
||||
#.#.#.#.#...#.......#.#.#...#.....#.....#.#.....#...#.#.#.#...#.#...#.#.#.......#.#...#.......#.....#.#...#...#...#.#.........#...#.#.....#.#
|
||||
#.#.#.#.#########.#.#.#####.#.#####.###.#.#.###.#.###.#.#.#####.#.###.#.#.#######.#.###.###.###.###.#.#.###.#.###.#.#########.###.#.###.#.#.#
|
||||
#.#.#.#...........#.#.......#.....#...#...#...#...#.#...#.....#...#...#.#.....#.......#.....#...#...#.#...#...#.....#.......#.#...#.....#.#.#
|
||||
#.#.#.#######.#.#.#.#######.#.###.###.#######.#####.#######.#.#.###.###.#####.#.###.#.#####.###.#.###.###.#####.#.#.#.###.#.#.#.#######.#.#.#
|
||||
#...#...#...#...#.#.....#.#.#.#...#.#...#...#.#.......#...#.#.#.....#.......#...............#...#.......#.....#.#...#.#...#.#...#.......#...#
|
||||
#.#.#.#.#.#######.###.#.#.#.#.#.#.#.###.#.#.#.#.#####.#.#.#.#.#######.#####.#.#.#.#.#.#.#####.#####.#########.#.#.#####.###.#####.#####.###.#
|
||||
#.......#...#...#.....#...#...#.#.....#...#.#...#...#...#...#.#.....#...............#...#.........#.#.......#...#.......#.#...#...........#.#
|
||||
#####.###.#.#.#.#.###.#######.#.#.###.#####.#####.#.#########.#.###.#.#.#.#.#.#.#.#.#.###.#######.###.###.#.#############.###.#.#######.#.#.#
|
||||
#.....#...#.#.#.......#.......#.....#...#.#.#...#.#.....#.....#.#...#.#.#.#.#...#.#...#...#.....#...#...#.#.....#...#...#.....#.#.......#.#.#
|
||||
#.###.#####.#.###.#####.#########.#.###.#.#.#.#.#.#####.#.#####.#####.#.###.###.#.#####.###.#####.#.#.###.#.###.###.#.#.#.#####.#.#####.#.#.#
|
||||
#.#.......#.#...#.......#.....#...#.#...#.#...#...#.....#...#...#.....#...#.#.....#...#.#.#.......#...#...#.....#...#.#.#.....#...#.....#.#.#
|
||||
#.#.#####.#.#.###.#########.#.#.#.#.#.###.#########.#######.#.###.#####.#.#.#.#.#.#.#.#.#.#.#####.#.###.###.#####.###.#.#####.#####.###.#.#.#
|
||||
#...#...#.#...#...#.......................#...#...#.......#.#.....#.......#...#.....#.#.#.......#...#...#.........#...#.#.....#.........#...#
|
||||
#.#####.#.###.#.#.#.#.###.###.#.#.#.#####.#.#.#.#.#.#####.#.#.#####.#####.#####.#####.#.#.#######.#.#.#####.#####.#.###.#.#####.#####.#.#.###
|
||||
#.#...#.#...#.#.....#...................................#...#...#...#.........#...#.#...#.#.....#...#.#.........#.#.#.#.#.....#.#...#...#...#
|
||||
#.#.#.#.###.#####.#.###.###.#.#.#.###.#.###.#.#.###.#.#########.#####.#######.#.#.#.#######.###.#.#.#.#.###.###.###.#.#.#####.###.#.#.#.###.#
|
||||
#S..#.....#.............#.......#.....#.....#.......#.................#.........#...........#.....#.#.........#.......#...........#...#.....#
|
||||
#############################################################################################################################################
|
15
day16/input_test.txt
Normal file
15
day16/input_test.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
###############
|
||||
#.......#....E#
|
||||
#.#.###.#.###.#
|
||||
#.....#.#...#.#
|
||||
#.###.#####.#.#
|
||||
#.#.#.......#.#
|
||||
#.#.#####.###.#
|
||||
#...........#.#
|
||||
###.#.#####.#.#
|
||||
#...#.....#.#.#
|
||||
#.#.#.###.#.#.#
|
||||
#.....#...#.#.#
|
||||
#.###.#.#.#.#.#
|
||||
#S..#.....#...#
|
||||
###############
|
17
day16/input_test2.txt
Normal file
17
day16/input_test2.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
#################
|
||||
#...#...#...#..E#
|
||||
#.#.#.#.#.#.#.#.#
|
||||
#.#.#.#...#...#.#
|
||||
#.#.#.#.###.#.#.#
|
||||
#...#.#.#.....#.#
|
||||
#.#.#.#.#.#####.#
|
||||
#.#...#.#.#.....#
|
||||
#.#.#####.#.###.#
|
||||
#.#.#.......#...#
|
||||
#.#.###.#####.###
|
||||
#.#.#...#.....#.#
|
||||
#.#.#.#####.###.#
|
||||
#.#.#.........#.#
|
||||
#.#.#.#########.#
|
||||
#S#.............#
|
||||
#################
|
84
day16/task.txt
Normal file
84
day16/task.txt
Normal file
@@ -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?
|
||||
|
Reference in New Issue
Block a user