Successful submission for day 07!
This commit is contained in:
parent
3ade35b6d7
commit
f6afc7a49c
2 changed files with 96 additions and 12 deletions
71
07/README.md
71
07/README.md
|
|
@ -127,3 +127,74 @@ This process continues until all of the tachyon beams reach a splitter or exit t
|
|||
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?
|
||||
|
||||
## --- Part Two ---
|
||||
|
||||
With your analysis of the manifold complete, you begin fixing the teleporter. However, as you open the side of the teleporter to replace the broken manifold, you are surprised to discover that it isn't a classical tachyon manifold - it's a quantum tachyon manifold.
|
||||
|
||||
With a quantum tachyon manifold, only a single tachyon particle is sent through the manifold. A tachyon particle takes both the left and right path of each splitter encountered.
|
||||
|
||||
Since this is impossible, the manual recommends the many-worlds interpretation of quantum tachyon splitting: each time a particle reaches a splitter, it's actually time itself which splits. In one timeline, the particle went left, and in the other timeline, the particle went right.
|
||||
|
||||
To fix the manifold, what you really need to know is the number of timelines active after a single particle completes all of its possible journeys through the manifold.
|
||||
|
||||
In the above example, there are many timelines. For instance, there's the timeline where the particle always went left:
|
||||
```txt
|
||||
.......S.......
|
||||
.......|.......
|
||||
......|^.......
|
||||
......|........
|
||||
.....|^.^......
|
||||
.....|.........
|
||||
....|^.^.^.....
|
||||
....|..........
|
||||
...|^.^...^....
|
||||
...|...........
|
||||
..|^.^...^.^...
|
||||
..|............
|
||||
.|^...^.....^..
|
||||
.|.............
|
||||
|^.^.^.^.^...^.
|
||||
|..............
|
||||
```
|
||||
Or, there's the timeline where the particle alternated going left and right at each splitter:
|
||||
```txt
|
||||
.......S.......
|
||||
.......|.......
|
||||
......|^.......
|
||||
......|........
|
||||
......^|^......
|
||||
.......|.......
|
||||
.....^|^.^.....
|
||||
......|........
|
||||
....^.^|..^....
|
||||
.......|.......
|
||||
...^.^.|.^.^...
|
||||
.......|.......
|
||||
..^...^|....^..
|
||||
.......|.......
|
||||
.^.^.^|^.^...^.
|
||||
......|........
|
||||
```
|
||||
Or, there's the timeline where the particle ends up at the same point as the alternating timeline, but takes a totally different path to get there:
|
||||
```txt
|
||||
.......S.......
|
||||
.......|.......
|
||||
......|^.......
|
||||
......|........
|
||||
.....|^.^......
|
||||
.....|.........
|
||||
....|^.^.^.....
|
||||
....|..........
|
||||
....^|^...^....
|
||||
.....|.........
|
||||
...^.^|..^.^...
|
||||
......|........
|
||||
..^..|^.....^..
|
||||
.....|.........
|
||||
.^.^.^|^.^...^.
|
||||
......|........
|
||||
```
|
||||
In this example, in total, the particle ends up on 40 different timelines.
|
||||
|
||||
Apply the many-worlds interpretation of quantum tachyon splitting to your manifold diagram. In total, how many different timelines would a single tachyon particle end up on?
|
||||
|
|
|
|||
37
07/main.py
37
07/main.py
|
|
@ -13,36 +13,49 @@ def parse_input(input_filepath: str) -> list[str]:
|
|||
return [s.strip() for s in input_data]
|
||||
|
||||
|
||||
def find_split_count(grid: list[str]) -> int:
|
||||
beams: set[int] = set([grid[0].find("S")])
|
||||
def find_split_count_and_timelines(grid: list[str]) -> tuple[int, int]:
|
||||
beam_sets: set[int] = set([grid[0].find("S")])
|
||||
beam_dict: dict = {grid[0].find("S"): 1}
|
||||
split_count = 0
|
||||
for row in grid[1:]:
|
||||
splitters: set[int] = set([i.start(0) for i in finditer("\\^", row)])
|
||||
for row in range(len(grid[1:])):
|
||||
splitters: set[int] = set([i.start(0) for i in finditer("\\^", grid[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)))))}"
|
||||
f"{"".join(list[str](map(lambda x: "|" if x in beam_sets else ("^" if x in splitters else "."), range(len(grid)))))}"
|
||||
)
|
||||
continue
|
||||
intersections = beams.intersection(splitters)
|
||||
differences = beams.difference(splitters)
|
||||
intersections = beam_sets.intersection(splitters)
|
||||
differences = beam_sets.difference(splitters)
|
||||
split_count += len(intersections)
|
||||
beams = (
|
||||
beam_sets = (
|
||||
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)
|
||||
)
|
||||
for i in intersections:
|
||||
temp_beams = beam_dict[i]
|
||||
beam_dict[i] = 0
|
||||
if (i - 1) in beam_dict.keys():
|
||||
beam_dict[i - 1] += temp_beams
|
||||
else:
|
||||
beam_dict[i - 1] = temp_beams
|
||||
if (i + 1) in beam_dict.keys():
|
||||
beam_dict[i + 1] += temp_beams
|
||||
else:
|
||||
beam_dict[i + 1] = temp_beams
|
||||
debug(
|
||||
f"{"".join(list[str](map(lambda x: "|" if x in beams else ("^" if x in splitters else "."), range(len(grid)))))}"
|
||||
f"{"".join(list[str](map(lambda x: "|" if x in beam_sets else ("^" if x in splitters else "."), range(len(grid)))))}"
|
||||
)
|
||||
return split_count
|
||||
return (split_count, sum(beam_dict.values()))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input_filepath = "input/grid.txt"
|
||||
input_grid = parse_input(input_filepath)
|
||||
split_count = find_split_count(input_grid)
|
||||
grid = parse_input(input_filepath)
|
||||
split_count, timelines = find_split_count_and_timelines(grid)
|
||||
print(f"The beam splits {split_count} times.")
|
||||
print(f"There are {timelines} possible beam timelines.")
|
||||
return
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue