Part 1 solved for day 07.
This commit is contained in:
parent
88815a5d19
commit
c4470e12bb
4 changed files with 340 additions and 0 deletions
129
07/README.md
Normal file
129
07/README.md
Normal file
|
|
@ -0,0 +1,129 @@
|
||||||
|
## --- Day 7: Laboratories ---
|
||||||
|
|
||||||
|
You thank the cephalopods for the help and exit the trash compactor, finding yourself in the familiar halls of a North Pole research wing.
|
||||||
|
|
||||||
|
Based on the large sign that says "teleporter hub", they seem to be researching teleportation; you can't help but try it for yourself and step onto the large yellow teleporter pad.
|
||||||
|
|
||||||
|
Suddenly, you find yourself in an unfamiliar room! The room has no doors; the only way out is the teleporter. Unfortunately, the teleporter seems to be leaking magic smoke.
|
||||||
|
|
||||||
|
Since this is a teleporter lab, there are lots of spare parts, manuals, and diagnostic equipment lying around. After connecting one of the diagnostic tools, it helpfully displays error code 0H-N0, which apparently means that there's an issue with one of the tachyon manifolds.
|
||||||
|
|
||||||
|
You quickly locate a diagram of the tachyon manifold (your puzzle input). A tachyon beam enters the manifold at the location marked S; tachyon beams always move downward. Tachyon beams pass freely through empty space (.). However, if a tachyon beam encounters a splitter (^), the beam is stopped; instead, a new tachyon beam continues from the immediate left and from the immediate right of the splitter.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
```txt
|
||||||
|
.......S.......
|
||||||
|
...............
|
||||||
|
.......^.......
|
||||||
|
...............
|
||||||
|
......^.^......
|
||||||
|
...............
|
||||||
|
.....^.^.^.....
|
||||||
|
...............
|
||||||
|
....^.^...^....
|
||||||
|
...............
|
||||||
|
...^.^...^.^...
|
||||||
|
...............
|
||||||
|
..^...^.....^..
|
||||||
|
...............
|
||||||
|
.^.^.^.^.^...^.
|
||||||
|
...............
|
||||||
|
```
|
||||||
|
In this example, the incoming tachyon beam (|) extends downward from S until it reaches the first splitter:
|
||||||
|
```txt
|
||||||
|
.......S.......
|
||||||
|
.......|.......
|
||||||
|
.......^.......
|
||||||
|
...............
|
||||||
|
......^.^......
|
||||||
|
...............
|
||||||
|
.....^.^.^.....
|
||||||
|
...............
|
||||||
|
....^.^...^....
|
||||||
|
...............
|
||||||
|
...^.^...^.^...
|
||||||
|
...............
|
||||||
|
..^...^.....^..
|
||||||
|
...............
|
||||||
|
.^.^.^.^.^...^.
|
||||||
|
...............
|
||||||
|
```
|
||||||
|
At that point, the original beam stops, and two new beams are emitted from the splitter:
|
||||||
|
```txt
|
||||||
|
.......S.......
|
||||||
|
.......|.......
|
||||||
|
......|^|......
|
||||||
|
...............
|
||||||
|
......^.^......
|
||||||
|
...............
|
||||||
|
.....^.^.^.....
|
||||||
|
...............
|
||||||
|
....^.^...^....
|
||||||
|
...............
|
||||||
|
...^.^...^.^...
|
||||||
|
...............
|
||||||
|
..^...^.....^..
|
||||||
|
...............
|
||||||
|
.^.^.^.^.^...^.
|
||||||
|
...............
|
||||||
|
```
|
||||||
|
Those beams continue downward until they reach more splitters:
|
||||||
|
```txt
|
||||||
|
.......S.......
|
||||||
|
.......|.......
|
||||||
|
......|^|......
|
||||||
|
......|.|......
|
||||||
|
......^.^......
|
||||||
|
...............
|
||||||
|
.....^.^.^.....
|
||||||
|
...............
|
||||||
|
....^.^...^....
|
||||||
|
...............
|
||||||
|
...^.^...^.^...
|
||||||
|
...............
|
||||||
|
..^...^.....^..
|
||||||
|
...............
|
||||||
|
.^.^.^.^.^...^.
|
||||||
|
...............
|
||||||
|
```
|
||||||
|
At this point, the two splitters create a total of only three tachyon beams, since they are both dumping tachyons into the same place between them:
|
||||||
|
```txt
|
||||||
|
.......S.......
|
||||||
|
.......|.......
|
||||||
|
......|^|......
|
||||||
|
......|.|......
|
||||||
|
.....|^|^|.....
|
||||||
|
...............
|
||||||
|
.....^.^.^.....
|
||||||
|
...............
|
||||||
|
....^.^...^....
|
||||||
|
...............
|
||||||
|
...^.^...^.^...
|
||||||
|
...............
|
||||||
|
..^...^.....^..
|
||||||
|
...............
|
||||||
|
.^.^.^.^.^...^.
|
||||||
|
...............
|
||||||
|
```
|
||||||
|
This process continues until all of the tachyon beams reach a splitter or exit the manifold:
|
||||||
|
```txt
|
||||||
|
.......S.......
|
||||||
|
.......|.......
|
||||||
|
......|^|......
|
||||||
|
......|.|......
|
||||||
|
.....|^|^|.....
|
||||||
|
.....|.|.|.....
|
||||||
|
....|^|^|^|....
|
||||||
|
....|.|.|.|....
|
||||||
|
...|^|^|||^|...
|
||||||
|
...|.|.|||.|...
|
||||||
|
..|^|^|||^|^|..
|
||||||
|
..|.|.|||.|.|..
|
||||||
|
.|^|||^||.||^|.
|
||||||
|
.|.|||.||.||.|.
|
||||||
|
|^|^|^|^|^|||^|
|
||||||
|
|.|.|.|.|.|||.|
|
||||||
|
```
|
||||||
|
To repair the teleporter, you first need to understand the beam-splitting properties of the tachyon manifold. In this example, a tachyon beam is split a total of 21 times.
|
||||||
|
|
||||||
|
Analyze your manifold diagram. How many times will the beam be split?
|
||||||
142
07/input/grid.txt
Normal file
142
07/input/grid.txt
Normal file
|
|
@ -0,0 +1,142 @@
|
||||||
|
......................................................................S......................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................................................^......................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................................................^.^.....................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................................................^.^.^....................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................................................^.^...^...................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................................................^.^.^.^.^..................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................................................^.^.^.^...^.................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................................................^.^...^.^.^.^................................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................................................^...^...^...^.^...............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................................................^.^.^.^.^.^...^.^..............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................................................^.....^.^.^.^...^.^.............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................................................^.^.^.^.^.^...^.^...^............................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................................................^...^.^.^.^.^...^.^.^.^...........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................................................^...^.^...^.^.^.....^...^..........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................................................^.^.^...^.^.^...^.^.^.^.^.^.........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................................................^...^...^.^.^.^.^...^...^...^........................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................................................^.........^.^.^.^.^.....^.^.^.^.......................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................................^.....^.^.^.^...^.^...^...^.....^......................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................................^.^.^.^.^...^...^.^.....^...^.^.^.^.....................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................................^...^.^...^...^...^.^.^...^.......^.^....................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................................^.^.....^.^.^.^...^.^...^.^.....^.^...^...................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................................^.^.^.^.^...^...^...^.^.^...^.^.^.^...^.^..................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................................^.^.......^.....^.^...^.^.^.....^...^.....^.................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................................^.^.....^...^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^................................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................................^.^.....^.^.^.^...^.^.^.^.^.^.^.^.^.....^.^.^.^...............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................................^.....^.^.^.^...^.^...^.^.^.^.^.....^.^.^.^.^...^..............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................................^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................................^.^.......^...^.^.^.^.....^.^...^...^...........^.^.^............................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................................^.^.^.^.^.^.^...^...^.^.^...^.^.......^...^.^.^.^.^.^.^...........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................................^.^...^.^.^.^.^.^.....^.^.....^.^.^.^.^.^.^.^...^.^...^.^..........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................................^.^.^.^...^...^.......^.^.^.^.^.^.^.^.^...^...^.^.....^.^.^.........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................................^.^...^.^.........^.^.....^...^.^...^...^.^...^...^.^.^...^.^........................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................................^.^.^.....^.^.^...^.......^.^.^.^.^...^.^.....^.^.^.^.^.^...^.^.......................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................................^.^.^.^.^...^.......^.^.^...^.^...^.^.^.^.^...^...^.^.^.^...^...^......................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................................^.^.^.^.^...^.^.^...^.....^.........^.....^.^.^...^.^.....^...^.^.^.....................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................................^.^...^.^.^.^.^.^.^.^...^.........^.....^...^.^.....^.^.^.^...^...^.^....................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................................^...^.^.^.^.^.^.^.^...^.....^.^...^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.^...................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................................^.^.^...^.^.^...^...^.^.^.^.^.^...^.^...^.^.^.^.^.^.^.^.^...^.^.........^..................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................................^.^.^.^.^.^.^.^...^.^.^.....^.^...^.^.^.^...^.^.^...^.^.^.^.^.....^.^.^.^.^.................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................................^...^.^.......^.....^...^.^...^...^.^.^...^.^.^.........^.^.^.^...^.^.^.^.^.^................................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............................^.^.^.^.^.^.^.....^.^.^.........^...^.^.^.^.^...^.^.^.^.^.....^...^.^.^.^.^.^.^...............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............................^.^.^...^.^...^.......^.^.^.^...^.....^...^.....^...^...^.^.^...^.^.^...^...^...^..............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............................^.^.^.........^...^.^.^.^.^.^.......^.^.^.^...^.....^.^.^.^.^.^.......^.^.^.^...^.^.............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
............................^...^.^...^.^.^.^...^.^.^...^.^.^.^.....^.^.^.^.^...^.....^.^.^.....^.^.^...^.^.^.^.^............................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........................^.^.^.^...^.^.^.^.^.^.^.^.^.^.....^.^...^.^.^...^.^.^...^.^...^.^.^.^.^.^...^.^...^.^.^...........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........................^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^...^.^.^.......^.^...^.^.^.^.^.^.........^...^.^...^.^..........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........................^.^.^...^.....^.....^.^.^.^.......^...^.^.^.^.^.....^...^.^.^.^.^...........^...^.^...^.^.^.........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
........................^.^.^.^.....^...^.^.^...^.^.^...^.^.^.^...........^...^.^.^.^.....^...^.^.^.^.^.^.^...^.^.^.^........................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......................^.^.^.^...^.^.^.^.^.^.....^.....^.^.^.^.^...^...^.^.^.^...^.^.^...^.^.^.^.^.....^.....^.^.^.^.^.......................
|
||||||
|
.............................................................................................................................................
|
||||||
|
......................^.^...^...^.^...^...^.^.^.^.^.......^.^.......^.^.^...^.......^.^...^.^...^.....^.^...^.^.....^.^......................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....................^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.......^.^.^...^.^.^.....^.^.^...^.........^.^...^.^.^...^.^.^...^.....................
|
||||||
|
.............................................................................................................................................
|
||||||
|
....................^...^.....^.^.....^.....^.......^.^.^.....^.^.^.^.^...^...^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^....................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...................^.^.^...........^...^.^.^.^.^.^.....^.......^.^.^.^.....^.^.....^...^.^...^...^.....^.^.^.^.^.......^.^...................
|
||||||
|
.............................................................................................................................................
|
||||||
|
..................^.....^...^.^.^.....^...^.....^.^.^.^...........^.^.^.^.^.^.^...^.^...^...^.^.^.^.^.^.^.^.^.^.^...^...^.^..................
|
||||||
|
.............................................................................................................................................
|
||||||
|
.................^.^.^.^.^.^...^.^...^.^...^.^.^.^.^...^.^.^.^.^...^.^.....^...^.^.^.^...^.^.^.^...^.^.^.^.^...^.....^.....^.................
|
||||||
|
.............................................................................................................................................
|
||||||
|
................^.^.^.......^.^...^.^.^.....^...^.^.......^...^.^...^...^...^...^.^.^.^.^.^...^.^...^.^.^...^.^...^.^.^.^.^.^................
|
||||||
|
.............................................................................................................................................
|
||||||
|
...............^...^.^.^.^...^.^...^.^.^.^.......^.................^.^...^.^.^.^...^.^.^.^...^...^.^.^...^...^.^.^.^.^.....^.^...............
|
||||||
|
.............................................................................................................................................
|
||||||
|
..............^.^.^.^...^...^.^.^.^.^.^.^...^.^.......^.^.^.^.^.^.......^.....^.^.^.^.^.^...^.^.^.^.........^.....^.^.....^...^..............
|
||||||
|
.............................................................................................................................................
|
||||||
|
.............^.....^...^...^...^.......^.^...^.^...........^.^.^.....^...^.^...^.^...^...^.....^.^.^...^...^.....^...^.^.^...^.^.............
|
||||||
|
.............................................................................................................................................
|
||||||
|
............^.....^.......^.^.^.^.^.^.^...^...^.......^.^...^.^.^...^.^.^.^.^.^...^...^.^.....^...^.^...^.^.^.^.^.......^.^.^...^............
|
||||||
|
.............................................................................................................................................
|
||||||
|
...........^.^...^.^.^...^.^.^.....^.^.^.^.......^.^.^.^...^.^...^.^.^...^.^...^...^...^.^.^.^.......^.^.^.^.^.^.^.^.^.^...^.^.^.^...........
|
||||||
|
.............................................................................................................................................
|
||||||
|
..........^.^.......^.^.^.^.^.^.^...^.^.^...^.^.^.^.....^.^.^...^...^...^.^.^.^...^.^.^.^.^.^...^.^.^...^.^...^.^.^...^...^.^.^...^..........
|
||||||
|
.............................................................................................................................................
|
||||||
|
.........^.^.^.^.^.^...^.....^.....^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^.^.....^.^.^...^.^.....^.^.^.^.....^.^...^.^.^.^...^...^.^.^.........
|
||||||
|
.............................................................................................................................................
|
||||||
|
........^...^.^.^...^.^.^.^...^.^.^.^...........^.^.^...^.^.^.....^...^.....^.^...^.^.^.^.^...^.^.^.^.^...^.^...^...^.^.^.^.^.^...^.^........
|
||||||
|
.............................................................................................................................................
|
||||||
|
.......^.....^.^.^.^...^.^.^...^.^.^.^.^.....^.....^.....^.^.^.....^.^.....^...^.^...^.^.^.^.^.^.^.^...^.^.....^.^.^.^...^.^.^...^.^.^.......
|
||||||
|
.............................................................................................................................................
|
||||||
|
......^.^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^...^.^...^.....^.^...^.^.^.^.......^.^.^.^.....^...^.^...^.^...^.^.^.^.^.^.^.^.^...^.^......
|
||||||
|
.............................................................................................................................................
|
||||||
|
.....^.^.^.^...^.^.^...^.^.^.^.....^.^.^.^.^...^.....^.....^.^.^.^...^...^.^.^.^.^.......^...^.^.^.......^.^...^.^.^.....^.^.^...^.^.^.^.....
|
||||||
|
.............................................................................................................................................
|
||||||
|
....^.^.^.^...^.^.^.^.....^.^...^...^...^.^.^...^.^.^.^.^.^...^.......^...^.^.^.^.^...^...^.^.......^.^.^.^.^.^.^.^.^...^.^.......^.^...^....
|
||||||
|
.............................................................................................................................................
|
||||||
|
...^...^...^.^...^...........^.^.^.^...^...^.^.^...^.....^.....^.^.^.^...^.^.^.........^.^.^.^.^.....^...^.^...^.....^.^...^...^.....^.^.^...
|
||||||
|
.............................................................................................................................................
|
||||||
|
..^.....^.^...^.......^...^.^...^...^.^...^...^...^...^.^.^.^.^.....^.^.^.^...^.^...^.^.^.^.......^.^.^...........^.....^...^.^...........^..
|
||||||
|
.............................................................................................................................................
|
||||||
|
.^.....^.^.^.^.^...^...^.^.^.^.......^.^.....^...^.^.^...^.....^.^.^.^.^.......^.^.....^...^.^.^.^.^.........^.....^.^.^...^.^.^.......^.^.^.
|
||||||
|
.............................................................................................................................................
|
||||||
16
07/input/test_grid.txt
Normal file
16
07/input/test_grid.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
.......S.......
|
||||||
|
...............
|
||||||
|
.......^.......
|
||||||
|
...............
|
||||||
|
......^.^......
|
||||||
|
...............
|
||||||
|
.....^.^.^.....
|
||||||
|
...............
|
||||||
|
....^.^...^....
|
||||||
|
...............
|
||||||
|
...^.^...^.^...
|
||||||
|
...............
|
||||||
|
..^...^.....^..
|
||||||
|
...............
|
||||||
|
.^.^.^.^.^...^.
|
||||||
|
...............
|
||||||
53
07/main.py
Executable file
53
07/main.py
Executable file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/bin/python
|
||||||
|
|
||||||
|
from logging import debug, DEBUG, basicConfig
|
||||||
|
from sys import argv
|
||||||
|
from re import finditer
|
||||||
|
|
||||||
|
|
||||||
|
def parse_input(input_filepath: str) -> list[str]:
|
||||||
|
|
||||||
|
with open(file=input_filepath, mode="r") as input_file:
|
||||||
|
input_data: list[str] = input_file.readlines()
|
||||||
|
|
||||||
|
return [s.strip() for s in input_data]
|
||||||
|
|
||||||
|
|
||||||
|
def find_split_count(grid: list[str]) -> int:
|
||||||
|
beams: set[int] = set([grid[0].find("S")])
|
||||||
|
split_count = 0
|
||||||
|
for row in grid[1:]:
|
||||||
|
splitters: set[int] = set([i.start(0) for i in finditer("\\^", row)])
|
||||||
|
if not splitters:
|
||||||
|
debug(
|
||||||
|
f"{"".join(list[str](map(lambda x: "|" if x in beams else ("^" if x in splitters else "."), range(len(grid)))))}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
intersections = beams.intersection(splitters)
|
||||||
|
differences = beams.difference(splitters)
|
||||||
|
split_count += len(intersections)
|
||||||
|
beams = (
|
||||||
|
set([x - 1 for x in intersections if x > 0])
|
||||||
|
.union([x + 1 for x in intersections if x < len(grid) - 2])
|
||||||
|
.union(differences)
|
||||||
|
.difference(splitters)
|
||||||
|
)
|
||||||
|
debug(
|
||||||
|
f"{"".join(list[str](map(lambda x: "|" if x in beams else ("^" if x in splitters else "."), range(len(grid)))))}"
|
||||||
|
)
|
||||||
|
return split_count
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
input_filepath = "input/grid.txt"
|
||||||
|
input_grid = parse_input(input_filepath)
|
||||||
|
split_count = find_split_count(input_grid)
|
||||||
|
print(f"The beam splits {split_count} times.")
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if "-d" in argv or "--debug" in argv:
|
||||||
|
basicConfig(filename="debug.log", level=DEBUG)
|
||||||
|
main()
|
||||||
|
exit(0)
|
||||||
Loading…
Reference in a new issue