From c4470e12bb2d780d5d7be59f33d53d4ee045527b Mon Sep 17 00:00:00 2001 From: Scarlette Winters Date: Sun, 7 Dec 2025 13:33:57 -0800 Subject: [PATCH] Part 1 solved for day 07. --- 07/README.md | 129 +++++++++++++++++++++++++++++++++++++ 07/input/grid.txt | 142 +++++++++++++++++++++++++++++++++++++++++ 07/input/test_grid.txt | 16 +++++ 07/main.py | 53 +++++++++++++++ 4 files changed, 340 insertions(+) create mode 100644 07/README.md create mode 100644 07/input/grid.txt create mode 100644 07/input/test_grid.txt create mode 100755 07/main.py diff --git a/07/README.md b/07/README.md new file mode 100644 index 0000000..a92fc81 --- /dev/null +++ b/07/README.md @@ -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? diff --git a/07/input/grid.txt b/07/input/grid.txt new file mode 100644 index 0000000..1374b31 --- /dev/null +++ b/07/input/grid.txt @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^.^.^.................................................................... +............................................................................................................................................. +...................................................................^.^...^................................................................... +............................................................................................................................................. +..................................................................^.^.^.^.^.................................................................. +............................................................................................................................................. +.................................................................^.^.^.^...^................................................................. +............................................................................................................................................. +................................................................^.^...^.^.^.^................................................................ +............................................................................................................................................. +...............................................................^...^...^...^.^............................................................... +............................................................................................................................................. +..............................................................^.^.^.^.^.^...^.^.............................................................. +............................................................................................................................................. +.............................................................^.....^.^.^.^...^.^............................................................. +............................................................................................................................................. +............................................................^.^.^.^.^.^...^.^...^............................................................ +............................................................................................................................................. +...........................................................^...^.^.^.^.^...^.^.^.^........................................................... +............................................................................................................................................. +..........................................................^...^.^...^.^.^.....^...^.......................................................... +............................................................................................................................................. +.........................................................^.^.^...^.^.^...^.^.^.^.^.^......................................................... +............................................................................................................................................. +........................................................^...^...^.^.^.^.^...^...^...^........................................................ +............................................................................................................................................. +.......................................................^.........^.^.^.^.^.....^.^.^.^....................................................... +............................................................................................................................................. +......................................................^.....^.^.^.^...^.^...^...^.....^...................................................... +............................................................................................................................................. +.....................................................^.^.^.^.^...^...^.^.....^...^.^.^.^..................................................... +............................................................................................................................................. +....................................................^...^.^...^...^...^.^.^...^.......^.^.................................................... +............................................................................................................................................. +...................................................^.^.....^.^.^.^...^.^...^.^.....^.^...^................................................... +............................................................................................................................................. +..................................................^.^.^.^.^...^...^...^.^.^...^.^.^.^...^.^.................................................. +............................................................................................................................................. +.................................................^.^.......^.....^.^...^.^.^.....^...^.....^................................................. +............................................................................................................................................. +................................................^.^.....^...^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^................................................ +............................................................................................................................................. +...............................................^.^.....^.^.^.^...^.^.^.^.^.^.^.^.^.....^.^.^.^............................................... +............................................................................................................................................. +..............................................^.....^.^.^.^...^.^...^.^.^.^.^.....^.^.^.^.^...^.............................................. +............................................................................................................................................. +.............................................^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^............................................. +............................................................................................................................................. +............................................^.^.......^...^.^.^.^.....^.^...^...^...........^.^.^............................................ +............................................................................................................................................. +...........................................^.^.^.^.^.^.^...^...^.^.^...^.^.......^...^.^.^.^.^.^.^........................................... +............................................................................................................................................. +..........................................^.^...^.^.^.^.^.^.....^.^.....^.^.^.^.^.^.^.^...^.^...^.^.......................................... +............................................................................................................................................. +.........................................^.^.^.^...^...^.......^.^.^.^.^.^.^.^.^...^...^.^.....^.^.^......................................... +............................................................................................................................................. +........................................^.^...^.^.........^.^.....^...^.^...^...^.^...^...^.^.^...^.^........................................ +............................................................................................................................................. +.......................................^.^.^.....^.^.^...^.......^.^.^.^.^...^.^.....^.^.^.^.^.^...^.^....................................... +............................................................................................................................................. +......................................^.^.^.^.^...^.......^.^.^...^.^...^.^.^.^.^...^...^.^.^.^...^...^...................................... +............................................................................................................................................. +.....................................^.^.^.^.^...^.^.^...^.....^.........^.....^.^.^...^.^.....^...^.^.^..................................... +............................................................................................................................................. +....................................^.^...^.^.^.^.^.^.^.^...^.........^.....^...^.^.....^.^.^.^...^...^.^.................................... +............................................................................................................................................. +...................................^...^.^.^.^.^.^.^.^...^.....^.^...^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.^................................... +............................................................................................................................................. +..................................^.^.^...^.^.^...^...^.^.^.^.^.^...^.^...^.^.^.^.^.^.^.^.^...^.^.........^.................................. +............................................................................................................................................. +.................................^.^.^.^.^.^.^.^...^.^.^.....^.^...^.^.^.^...^.^.^...^.^.^.^.^.....^.^.^.^.^................................. +............................................................................................................................................. +................................^...^.^.......^.....^...^.^...^...^.^.^...^.^.^.........^.^.^.^...^.^.^.^.^.^................................ +............................................................................................................................................. +...............................^.^.^.^.^.^.^.....^.^.^.........^...^.^.^.^.^...^.^.^.^.^.....^...^.^.^.^.^.^.^............................... +............................................................................................................................................. +..............................^.^.^...^.^...^.......^.^.^.^...^.....^...^.....^...^...^.^.^...^.^.^...^...^...^.............................. +............................................................................................................................................. +.............................^.^.^.........^...^.^.^.^.^.^.......^.^.^.^...^.....^.^.^.^.^.^.......^.^.^.^...^.^............................. +............................................................................................................................................. +............................^...^.^...^.^.^.^...^.^.^...^.^.^.^.....^.^.^.^.^...^.....^.^.^.....^.^.^...^.^.^.^.^............................ +............................................................................................................................................. +...........................^.^.^.^...^.^.^.^.^.^.^.^.^.^.....^.^...^.^.^...^.^.^...^.^...^.^.^.^.^.^...^.^...^.^.^........................... +............................................................................................................................................. +..........................^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^...^.^.^.......^.^...^.^.^.^.^.^.........^...^.^...^.^.......................... +............................................................................................................................................. +.........................^.^.^...^.....^.....^.^.^.^.......^...^.^.^.^.^.....^...^.^.^.^.^...........^...^.^...^.^.^......................... +............................................................................................................................................. +........................^.^.^.^.....^...^.^.^...^.^.^...^.^.^.^...........^...^.^.^.^.....^...^.^.^.^.^.^.^...^.^.^.^........................ +............................................................................................................................................. +.......................^.^.^.^...^.^.^.^.^.^.....^.....^.^.^.^.^...^...^.^.^.^...^.^.^...^.^.^.^.^.....^.....^.^.^.^.^....................... +............................................................................................................................................. +......................^.^...^...^.^...^...^.^.^.^.^.......^.^.......^.^.^...^.......^.^...^.^...^.....^.^...^.^.....^.^...................... +............................................................................................................................................. +.....................^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.......^.^.^...^.^.^.....^.^.^...^.........^.^...^.^.^...^.^.^...^..................... +............................................................................................................................................. +....................^...^.....^.^.....^.....^.......^.^.^.....^.^.^.^.^...^...^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^.................... +............................................................................................................................................. +...................^.^.^...........^...^.^.^.^.^.^.....^.......^.^.^.^.....^.^.....^...^.^...^...^.....^.^.^.^.^.......^.^................... +............................................................................................................................................. +..................^.....^...^.^.^.....^...^.....^.^.^.^...........^.^.^.^.^.^.^...^.^...^...^.^.^.^.^.^.^.^.^.^.^...^...^.^.................. +............................................................................................................................................. +.................^.^.^.^.^.^...^.^...^.^...^.^.^.^.^...^.^.^.^.^...^.^.....^...^.^.^.^...^.^.^.^...^.^.^.^.^...^.....^.....^................. +............................................................................................................................................. +................^.^.^.......^.^...^.^.^.....^...^.^.......^...^.^...^...^...^...^.^.^.^.^.^...^.^...^.^.^...^.^...^.^.^.^.^.^................ +............................................................................................................................................. +...............^...^.^.^.^...^.^...^.^.^.^.......^.................^.^...^.^.^.^...^.^.^.^...^...^.^.^...^...^.^.^.^.^.....^.^............... +............................................................................................................................................. +..............^.^.^.^...^...^.^.^.^.^.^.^...^.^.......^.^.^.^.^.^.......^.....^.^.^.^.^.^...^.^.^.^.........^.....^.^.....^...^.............. +............................................................................................................................................. +.............^.....^...^...^...^.......^.^...^.^...........^.^.^.....^...^.^...^.^...^...^.....^.^.^...^...^.....^...^.^.^...^.^............. +............................................................................................................................................. +............^.....^.......^.^.^.^.^.^.^...^...^.......^.^...^.^.^...^.^.^.^.^.^...^...^.^.....^...^.^...^.^.^.^.^.......^.^.^...^............ +............................................................................................................................................. +...........^.^...^.^.^...^.^.^.....^.^.^.^.......^.^.^.^...^.^...^.^.^...^.^...^...^...^.^.^.^.......^.^.^.^.^.^.^.^.^.^...^.^.^.^........... +............................................................................................................................................. +..........^.^.......^.^.^.^.^.^.^...^.^.^...^.^.^.^.....^.^.^...^...^...^.^.^.^...^.^.^.^.^.^...^.^.^...^.^...^.^.^...^...^.^.^...^.......... +............................................................................................................................................. +.........^.^.^.^.^.^...^.....^.....^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^.^.....^.^.^...^.^.....^.^.^.^.....^.^...^.^.^.^...^...^.^.^......... +............................................................................................................................................. +........^...^.^.^...^.^.^.^...^.^.^.^...........^.^.^...^.^.^.....^...^.....^.^...^.^.^.^.^...^.^.^.^.^...^.^...^...^.^.^.^.^.^...^.^........ +............................................................................................................................................. +.......^.....^.^.^.^...^.^.^...^.^.^.^.^.....^.....^.....^.^.^.....^.^.....^...^.^...^.^.^.^.^.^.^.^...^.^.....^.^.^.^...^.^.^...^.^.^....... +............................................................................................................................................. +......^.^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^...^.^...^.....^.^...^.^.^.^.......^.^.^.^.....^...^.^...^.^...^.^.^.^.^.^.^.^.^...^.^...... +............................................................................................................................................. +.....^.^.^.^...^.^.^...^.^.^.^.....^.^.^.^.^...^.....^.....^.^.^.^...^...^.^.^.^.^.......^...^.^.^.......^.^...^.^.^.....^.^.^...^.^.^.^..... +............................................................................................................................................. +....^.^.^.^...^.^.^.^.....^.^...^...^...^.^.^...^.^.^.^.^.^...^.......^...^.^.^.^.^...^...^.^.......^.^.^.^.^.^.^.^.^...^.^.......^.^...^.... +............................................................................................................................................. +...^...^...^.^...^...........^.^.^.^...^...^.^.^...^.....^.....^.^.^.^...^.^.^.........^.^.^.^.^.....^...^.^...^.....^.^...^...^.....^.^.^... +............................................................................................................................................. +..^.....^.^...^.......^...^.^...^...^.^...^...^...^...^.^.^.^.^.....^.^.^.^...^.^...^.^.^.^.......^.^.^...........^.....^...^.^...........^.. +............................................................................................................................................. +.^.....^.^.^.^.^...^...^.^.^.^.......^.^.....^...^.^.^...^.....^.^.^.^.^.......^.^.....^...^.^.^.^.^.........^.....^.^.^...^.^.^.......^.^.^. +............................................................................................................................................. diff --git a/07/input/test_grid.txt b/07/input/test_grid.txt new file mode 100644 index 0000000..57a2466 --- /dev/null +++ b/07/input/test_grid.txt @@ -0,0 +1,16 @@ +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +............... diff --git a/07/main.py b/07/main.py new file mode 100755 index 0000000..45850c2 --- /dev/null +++ b/07/main.py @@ -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)