generated from public/aoc_template
Compare commits
No commits in common. "89e37bc290f4dfa59d70a0ad18085fed47a3ca99" and "2d8384c29e8c009d668e1acf3110af48aa0d09da" have entirely different histories.
89e37bc290
...
2d8384c29e
69
day06.py
69
day06.py
@ -1,69 +0,0 @@
|
|||||||
from tools.aoc import AOCDay
|
|
||||||
from typing import Any
|
|
||||||
from tools.coordinate import Coordinate
|
|
||||||
from tools.grid import Grid
|
|
||||||
|
|
||||||
DIRECTIONS = [(0, -1), (1, 0), (0, 1), (-1, 0)]
|
|
||||||
|
|
||||||
|
|
||||||
def walk_room(grid: Grid, start: Coordinate) -> tuple[set, bool]:
|
|
||||||
cur_pos = start
|
|
||||||
dir_index = 0
|
|
||||||
visited = set()
|
|
||||||
while grid.isWithinBoundaries(cur_pos):
|
|
||||||
if (cur_pos, dir_index) in visited:
|
|
||||||
return set(x[0] for x in visited), True
|
|
||||||
|
|
||||||
visited.add((cur_pos, dir_index))
|
|
||||||
next_pos = cur_pos + DIRECTIONS[dir_index]
|
|
||||||
while grid.get(next_pos):
|
|
||||||
dir_index = (dir_index + 1) % len(DIRECTIONS)
|
|
||||||
next_pos = cur_pos + DIRECTIONS[dir_index]
|
|
||||||
|
|
||||||
cur_pos = next_pos
|
|
||||||
|
|
||||||
return visited, False
|
|
||||||
|
|
||||||
|
|
||||||
class Day(AOCDay):
|
|
||||||
inputs = [
|
|
||||||
[
|
|
||||||
(41, "input6_test"),
|
|
||||||
(5208, "input6"),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
(6, "input6_test"),
|
|
||||||
(1972, "input6"),
|
|
||||||
],
|
|
||||||
]
|
|
||||||
|
|
||||||
def parse_input(self) -> tuple[Grid, Coordinate]:
|
|
||||||
grid = Grid.from_data(self.getInput(), translate={".": False, "#": True})
|
|
||||||
start = list(grid.find("^"))[0]
|
|
||||||
grid.set(start, False)
|
|
||||||
|
|
||||||
return grid, start
|
|
||||||
|
|
||||||
def part1(self) -> Any:
|
|
||||||
grid, cur_pos = self.parse_input()
|
|
||||||
return len(set(x[0] for x in walk_room(grid, cur_pos)[0]))
|
|
||||||
|
|
||||||
def part2(self) -> Any:
|
|
||||||
grid, start = self.parse_input()
|
|
||||||
visits = set(x[0] for x in walk_room(grid, start)[0])
|
|
||||||
|
|
||||||
loops = 0
|
|
||||||
for obs_pos in visits:
|
|
||||||
if obs_pos == start:
|
|
||||||
continue
|
|
||||||
|
|
||||||
grid.set(obs_pos, True)
|
|
||||||
loops += walk_room(grid, start)[1]
|
|
||||||
grid.set(obs_pos, False)
|
|
||||||
|
|
||||||
return loops
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
day = Day(2024, 6)
|
|
||||||
day.run(verbose=True)
|
|
||||||
130
inputs/input6
130
inputs/input6
@ -1,130 +0,0 @@
|
|||||||
...............................#.........#............#...#.............................#....................#.....#........##....
|
|
||||||
..##..##.#.#....................##....#..#.....#...............#..#.....#.....................#...#.............#...#...#.........
|
|
||||||
...................#............#..................................................#............................#..#..............
|
|
||||||
............#...................................................#.........................#..#....#....................#..........
|
|
||||||
.#...........#...............................#..#....................................#............#.#............#................
|
|
||||||
.........................#..........................................#.................#...#.....#.#...............................
|
|
||||||
..#..................#......................................#......#........#.......#..........#.........#..#.........#...........
|
|
||||||
..........#..............#....................................#................................................#........#........#
|
|
||||||
..#...............................................................................................................#.#..#..........
|
|
||||||
....#....................##...................#..#....#....#.........#.......#.....................................#..............
|
|
||||||
........#...................#.......#.........................................#.........#........#....................#...........
|
|
||||||
................................................................#.......#......#...........#................#.....................
|
|
||||||
...........................................#.............#...........##.#................................#...................#....
|
|
||||||
............................#......#........#...#.................................................................................
|
|
||||||
.......#.............#...............................#.............................................#.............#.........#......
|
|
||||||
......................................................#.........................#....#................................#...........
|
|
||||||
...............#...........................................#..........#.........#..#..................#...........................
|
|
||||||
.....................................##...#................................#..#......................#.......#..........#.........
|
|
||||||
..............#.......#....................#.....................................................#.......#...................##..#
|
|
||||||
...............................................#.............#..#...#.....#..................................................#....
|
|
||||||
.....................................#........#...........................................................#......#................
|
|
||||||
........##............#...............................#....#......................................................................
|
|
||||||
.....#............#...................................................................#.............................#.............
|
|
||||||
........#...............#......#..........#........#.....#........#..........#...............................................#..#.
|
|
||||||
..................#.............#........#......#.................................................#..........................#....
|
|
||||||
.................................#............#...............................................................#..##...............
|
|
||||||
......................................#.#...........#........#.................................................................#..
|
|
||||||
...........#...........#..............#..#.#...........#............................................#...#.....................#...
|
|
||||||
....##......................#..........#..............#.............#.....#............................#....................#.....
|
|
||||||
..................#...................#..........#............................................#...#.....................#.........
|
|
||||||
.....................#...........#.........................................................#......................................
|
|
||||||
.#..............#....#..#.#...##.........#....#.............#..........#.......#...#.............................#.........#...#..
|
|
||||||
..................#...............#.....................#..#.....................#........#.......................................
|
|
||||||
......#..#......#...#..................##.............#...................#.....#.....#................................#........#.
|
|
||||||
....................#.#................#....#..................................................#............#................#....
|
|
||||||
...........................#..#.#......#........................#......#..........................................................
|
|
||||||
..#.#...............................................................#.#........................#.....................#..#.........
|
|
||||||
...#..............................#......................................................#...#....................#.#.............
|
|
||||||
....................#.......#...........#.....#.......................#........#...........................##.....................
|
|
||||||
............#.........................................................#..............................................#.........#..
|
|
||||||
..................#.#..............................#......#..................................#..........#......#..#...............
|
|
||||||
....##................#.#..................#.....#...........................................#.......................##...........
|
|
||||||
......#...........................#......#.......#..........#................#..#......#..........#..............#..#.............
|
|
||||||
........#.................#...#.........................................#..........#.........#...................................#
|
|
||||||
.#..........#....#.....#.............#...........#..................#.................#...#.......................................
|
|
||||||
...........................................................#......#...#...........................................##........#....#
|
|
||||||
............#.............................................................................#..........................#............
|
|
||||||
.........#..............................................................................................#.........#.....#......#..
|
|
||||||
.........#.......................................................................#........................#..#.....#.#............
|
|
||||||
............................#.............#..........#..#...........#......#..............#..........................#............
|
|
||||||
..#.#............#.........#.........#..................#.......................#............................................#....
|
|
||||||
...#......................#......................................................#...........#..........................#.........
|
|
||||||
.#....#...............................................................................................................#...........
|
|
||||||
.#..#................#................................................................#....^.................#.............#......
|
|
||||||
........................................................................................#.....................#...................
|
|
||||||
........##................#.............................#.........................................................................
|
|
||||||
.#.#.................#.....................#.....................#..........................#.................#...............#...
|
|
||||||
........#....................................................................................................#....................
|
|
||||||
##......#.............................#.......#........................................................................#.....##...
|
|
||||||
..........#..........................................#.................#.....#............................................#.......
|
|
||||||
......................#........................#.......................................#............#.............................
|
|
||||||
.............................#.#.......................................................................................#..........
|
|
||||||
...#.........#.....#........................#.................#...........#.....................#.................................
|
|
||||||
.........#...........................................................................#...........................#................
|
|
||||||
......#...#............#..........#........................#...................#...........#................................#.....
|
|
||||||
.....#...#....#..........................................................#......................#.....................#..........#
|
|
||||||
#.............#....................#...............................#.......#.#.............#.....................#.............#..
|
|
||||||
............................................................#.......#...................#.................................#......#
|
|
||||||
...#..#......................................#.........................................#..#.#.......##.......#............#..#....
|
|
||||||
.....#.#...#...#.#................................................................................................................
|
|
||||||
...............................................................................#........#...................#..#.........#....#...
|
|
||||||
......#.........#.............#........................................................................................#.##.......
|
|
||||||
.......................#...................................................................................................#......
|
|
||||||
.........................................................#....................................#...................##.........#....
|
|
||||||
.#..............#.#.#.............................#........................#........................#...................#.#.......
|
|
||||||
.........#.....#..........................................................................#.................#.................#...
|
|
||||||
.........#..............#...............................#.........#......#.#......................................................
|
|
||||||
......................................................................................................#....#............#.......#.
|
|
||||||
.....#.................#.......#.....#..................................#...............................................#.........
|
|
||||||
...............................................................#.............#.................................................#..
|
|
||||||
...#.....................................................................#...#.......#......#.....................................
|
|
||||||
.................................#...#.#............................................................#...#.........................
|
|
||||||
...........#..#.................................#....#...................#.............#.........#................................
|
|
||||||
..................................................#..#...........#...........................#....................................
|
|
||||||
.....#.....................................#......#......#...........................................................#............
|
|
||||||
..............#..........................................#.........#.............#..#............................#................
|
|
||||||
..........................................................................#..........#.......................#....................
|
|
||||||
.......##................#................................................................................................#.......
|
|
||||||
.#.....#.....#..................#............#......#............................#.........#......................................
|
|
||||||
..##....#..................................................................................................................#......
|
|
||||||
.......#......................#..................#...#.....................................#............#..............#..........
|
|
||||||
...............................#................#...#.................................##......................#...................
|
|
||||||
...............#..............................................................................................#.....##.......#....
|
|
||||||
................................#..........#........................................#..#..........................................
|
|
||||||
..................................................#.................................................................#.............
|
|
||||||
....................#....#.....................#.................................#.........#.....#......#......................#..
|
|
||||||
................#.............#............#................#........................................................#..........#.
|
|
||||||
.#.......#......##...................#....#..............................................................#.................#......
|
|
||||||
.........#.#............................................................................#........................#................
|
|
||||||
...............#........##.....#.....................................#..#...........#......#......................................
|
|
||||||
......#.............................................###..#.........#..............#...........................#.......#...........
|
|
||||||
.....................................#.........#...........................................................##.....................
|
|
||||||
.#....#.......................#.........#................................................................................#..#.....
|
|
||||||
....#..#.......................................................................................................##............#....
|
|
||||||
..#...................................#....#......#....................#...............................#..........................
|
|
||||||
...................#....##........................................##..........................................#...................
|
|
||||||
..........#.........#.............................................................#..#.........#...#............#.......#..#......
|
|
||||||
....#...........#...##.........................#......................#.........#..#..............................................
|
|
||||||
....................#.....#.....................................#...............................................................#.
|
|
||||||
.........#.......................#.................#...#....................................................#.#......#........#...
|
|
||||||
.................#.................................#..#..............#..........#...#.........#........#.##....##.................
|
|
||||||
.............#...........................#......................#.......................#.........................................
|
|
||||||
...............#.....#......#........#....#.......................................#.............................#.................
|
|
||||||
.............#.....##.........#...#...............................................................................................
|
|
||||||
.................................................................................#.............#.....#...#..#.....................
|
|
||||||
.................................#......#.#...#.......#......................................#......#..........................#..
|
|
||||||
#..#....................................#..#......................................................................................
|
|
||||||
...#......#.......................#..........................#...........#.#................#.#.......#...........................
|
|
||||||
#....#...............#..........................#....................#....#................................#............##........
|
|
||||||
...........#........................#..........#......................................#...................................#.....#.
|
|
||||||
......#................................#................#.............................#.........#...#........#....................
|
|
||||||
.............#................#...........#.#...........#.......................................#...........#.#...................
|
|
||||||
.....#......................#..........................#.................................#.............#............#....#........
|
|
||||||
.....#.........#.#..............................................................................#...................##............
|
|
||||||
......#.....#..#.............#...............#......#..#.#.................................#...............#...#..................
|
|
||||||
....................#.......................#...................#........................#...................#..#.....##..........
|
|
||||||
...............#...........#..#...........................................#........................#....#.........................
|
|
||||||
.....................................#...................#.#............#......................................#..................
|
|
||||||
.....#......................#.#....................#.............................................#...........................#..#.
|
|
||||||
..........#........#................#.........#...........................................#....#..#...........#..####..........#..
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
....#.....
|
|
||||||
.........#
|
|
||||||
..........
|
|
||||||
..#.......
|
|
||||||
.......#..
|
|
||||||
..........
|
|
||||||
.#..^.....
|
|
||||||
........#.
|
|
||||||
#.........
|
|
||||||
......#...
|
|
||||||
Loading…
Reference in New Issue
Block a user