Compare commits

...

15 commits

Author SHA1 Message Date
0db22655f9 Merge branch 'day-08' 2025-12-08 18:04:57 -08:00
e317f8cb9d Successful submission for day 08! 2025-12-08 18:04:45 -08:00
02113adb0e Working on day 08. 2025-12-08 14:47:53 -08:00
Scarlette Winters
19915835d4 Cleaning up code. 2025-12-07 17:45:38 -08:00
Scarlette Winters
76a75f532f Successful submission for day 07! 2025-12-07 17:26:10 -08:00
Scarlette Winters
c4470e12bb Part 1 solved for day 07. 2025-12-07 13:33:57 -08:00
88815a5d19 Merge pull request 'Implementing Day 05's Solution in C++' (#1) from cpp into main
Reviewed-on: #1
2025-12-06 21:58:30 -06:00
2a58978931 I am so glad I never *have* to write C++ again. 2025-12-06 19:56:43 -08:00
c6caab0c7e Attempting in c++ 2025-12-06 14:38:52 -08:00
56e423fe97 Successful submission for day 06! 2025-12-06 13:08:49 -08:00
4d75e5ebb8 Working on day 06. 2025-12-06 13:08:36 -06:00
1ac490ded0 Remove unnecessary debug statement. 2025-12-05 11:54:19 -08:00
ac4da31dd4 Completed submission for day 05! 2025-12-05 11:37:46 -08:00
b6fda004b9 Completed submission for day 04! 2025-12-04 13:48:03 -08:00
Scarlette Winters
54c65907fb Working on it. 2025-12-03 22:12:38 -08:00
4 changed files with 1187 additions and 0 deletions

62
08/README.md Normal file
View file

@ -0,0 +1,62 @@
# --- Day 8: Playground ---
Equipped with a new understanding of teleporter maintenance, you confidently step onto the repaired teleporter pad.
You rematerialize on an unfamiliar teleporter pad and find yourself in a vast underground space which contains a giant playground!
Across the playground, a group of Elves are working on setting up an ambitious Christmas decoration project. Through careful rigging, they have suspended a large number of small electrical junction boxes.
Their plan is to connect the junction boxes with long strings of lights. Most of the junction boxes don't provide electricity; however, when two junction boxes are connected by a string of lights, electricity can pass between those two junction boxes.
The Elves are trying to figure out which junction boxes to connect so that electricity can reach every junction box. They even have a list of all of the junction boxes' positions in 3D space (your puzzle input).
For example:
```txt
162,817,812
57,618,57
906,360,560
592,479,940
352,342,300
466,668,158
542,29,236
431,825,988
739,650,466
52,470,668
216,146,977
819,987,18
117,168,530
805,96,715
346,949,466
970,615,88
941,993,340
862,61,35
984,92,344
425,690,689
```
This list describes the position of 20 junction boxes, one per line. Each position is given as X,Y,Z coordinates. So, the first junction box in the list is at X=162, Y=817, Z=812.
To save on string lights, the Elves would like to focus on connecting pairs of junction boxes that are as close together as possible according to straight-line distance. In this example, the two junction boxes which are closest together are 162,817,812 and 425,690,689.
By connecting these two junction boxes together, because electricity can flow between them, they become part of the same circuit. After connecting them, there is a single circuit which contains two junction boxes, and the remaining 18 junction boxes remain in their own individual circuits.
Now, the two junction boxes which are closest together but aren't already directly connected are 162,817,812 and 431,825,988. After connecting them, since 162,817,812 is already connected to another junction box, there is now a single circuit which contains three junction boxes and an additional 17 circuits which contain one junction box each.
The next two junction boxes to connect are 906,360,560 and 805,96,715. After connecting them, there is a circuit containing 3 junction boxes, a circuit containing 2 junction boxes, and 15 circuits which contain one junction box each.
The next two junction boxes are 431,825,988 and 425,690,689. Because these two junction boxes were already in the same circuit, nothing happens!
This process continues for a while, and the Elves are concerned that they don't have enough extension cables for all these circuits. They would like to know how big the circuits will be.
After making the ten shortest connections, there are 11 circuits: one circuit which contains 5 junction boxes, one circuit which contains 4 junction boxes, two circuits which contain 2 junction boxes each, and seven circuits which each contain a single junction box. Multiplying together the sizes of the three largest circuits (5, 4, and one of the circuits of size 2) produces 40.
Your list contains many junction boxes; connect together the 1000 pairs of junction boxes which are closest together. Afterward, what do you get if you multiply together the sizes of the three largest circuits?
## --- Part Two ---
The Elves were right; they definitely don't have enough extension cables. You'll need to keep connecting junction boxes together until they're all in one large circuit.
Continuing the above example, the first connection which causes all of the junction boxes to form a single circuit is between the junction boxes at 216,146,977 and 117,168,530. The Elves need to know how far those junction boxes are from the wall so they can pick the right extension cable; multiplying the X coordinates of those two junction boxes (216 and 117) produces 25272.
Continue connecting the closest unconnected pairs of junction boxes together until they're all in the same circuit. What do you get if you multiply together the X coordinates of the last two junction boxes you need to connect?

1000
08/input/junction_boxes.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,20 @@
162,817,812
57,618,57
906,360,560
592,479,940
352,342,300
466,668,158
542,29,236
431,825,988
739,650,466
52,470,668
216,146,977
819,987,18
117,168,530
805,96,715
346,949,466
970,615,88
941,993,340
862,61,35
984,92,344
425,690,689

105
08/main.py Executable file
View file

@ -0,0 +1,105 @@
#!/bin/python
from logging import debug, DEBUG, basicConfig
from sys import argv
def parse_input(input_filepath: str) -> list[tuple[int, ...]]:
with open(file=input_filepath, mode="r") as input_file:
input_data: list[str] = input_file.readlines()
debug(f"RAW INPUT: {input_data}")
return [tuple(int(y) for y in x.split(",")) for x in input_data]
def get_distances(positions: list[tuple[int, ...]]) -> list[tuple[float, int, int]]:
distances: list[tuple[float, int, int]] = []
for a in range(len(positions)):
for b in range(a + 1, len(positions)):
distances.append(
(
pow(positions[a][0] - positions[b][0], 2)
+ pow(positions[a][1] - positions[b][1], 2)
+ pow(positions[a][2] - positions[b][2], 2),
a,
b,
)
)
distances.sort(key=lambda x: x[0])
return distances
def create_circuits(
distances: list[tuple[float, int, int]], n: int
) -> tuple[list[int], tuple[float, int, int]]:
single_circuits: list[int] = [x for x in range(n)]
circuits: list[set[int]] = []
count = 0
circuits_after_n: list[int] = []
for d in distances:
if count == 999:
circuits_after_n = [len(x) for x in circuits]
if len(single_circuits) == 0 and len(circuits) == 1:
break
count += 1
debug(f"Current Iteration: {count} | {d} | {circuits}")
a_in_single_circuits = d[1] in single_circuits
b_in_single_circuits = d[2] in single_circuits
if a_in_single_circuits or b_in_single_circuits:
if a_in_single_circuits and b_in_single_circuits:
circuits.append(set([d[1], d[2]]))
single_circuits.remove(d[1])
single_circuits.remove(d[2])
continue
for c in circuits:
if d[1] in c:
c.add(d[2])
single_circuits.remove(d[2])
break
if d[2] in c:
c.add(d[1])
single_circuits.remove(d[1])
break
continue
circuit_a = circuit_b = set()
for c in circuits:
if d[1] in c:
circuit_a = c
if d[2] in c:
circuit_b = c
if circuit_a == circuit_b:
continue
circuits.remove(circuit_a)
circuits.remove(circuit_b)
circuits.append(circuit_a.union(circuit_b))
return (circuits_after_n, distances[count - 1])
def main() -> None:
input_filepath = "input/junction_boxes.txt"
junction_boxes = parse_input(input_filepath)
distances = get_distances(junction_boxes)
debug(f"DISTANCES BETWEEN BOXES: {distances}")
circuits_after_n, final_distance = create_circuits(distances, len(junction_boxes))
debug(f"CIRCUITS CREATED AFTER 1000 ITERATIONS: {circuits_after_n}")
debug(f"FINAL DISTANCE EXAMINED: {final_distance[0]} | {junction_boxes[final_distance[1]]} | {junction_boxes[final_distance[2]]}")
circuits_after_n.sort(reverse=True)
product_of_n_largest_circuits = (
circuits_after_n[0] * circuits_after_n[1] * circuits_after_n[2]
)
print(
f"The product of the three largest circuits after 1000 iterations is: {product_of_n_largest_circuits}"
)
print(
f"The product of the x coordinates of the last two junction boxes connected: {junction_boxes[final_distance[1]][0] * junction_boxes[final_distance[2]][0]}"
)
return
if __name__ == "__main__":
if "-d" in argv or "--debug" in argv:
basicConfig(filename="debug.log", level=DEBUG)
main()
exit(0)