Compare commits

...

11 commits

25 changed files with 2662 additions and 1 deletions

6
.gitignore vendored
View file

@ -1,3 +1,7 @@
.pyc
*/__pycache__/*
*.log
*.log
*/main
**/*.o
.vscode
.mypy_cache

179
04/README.md Normal file
View file

@ -0,0 +1,179 @@
# --- Day 4: Printing Department ---
You ride the escalator down to the printing department. They're clearly getting ready for Christmas; they have lots of large rolls of paper everywhere, and there's even a massive printer in the corner (to handle the really big print jobs).
Decorating here will be easy: they can make their own decorations. What you really need is a way to get further into the North Pole base while the elevators are offline.
"Actually, maybe we can help with that," one of the Elves replies when you ask for help. "We're pretty sure there's a cafeteria on the other side of the back wall. If we could break through the wall, you'd be able to keep moving. It's too bad all of our forklifts are so busy moving those big rolls of paper around."
If you can optimize the work the forklifts are doing, maybe they would have time to spare to break through the wall.
The rolls of paper (@) are arranged on a large grid; the Elves even have a helpful diagram (your puzzle input) indicating where everything is located.
For example:
```txt
..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.
```
The forklifts can only access a roll of paper if there are fewer than four rolls of paper in the eight adjacent positions. If you can figure out which rolls of paper the forklifts can access, they'll spend less time looking and more time breaking down the wall to the cafeteria.
In this example, there are 13 rolls of paper that can be accessed by a forklift (marked with x):
```txt
..xx.xx@x.
x@@.@.@.@@
@@@@@.x.@@
@.@@@@..@.
x@.@@@@.@x
.@@@@@@@.@
.@.@.@.@@@
x.@@@.@@@@
.@@@@@@@@.
x.x.@@@.x.
```
Consider your complete diagram of the paper roll locations. How many rolls of paper can be accessed by a forklift?
## --- Part Two ---
Now, the Elves just need help accessing as much of the paper as they can.
Once a roll of paper can be accessed by a forklift, it can be removed. Once a roll of paper is removed, the forklifts might be able to access more rolls of paper, which they might also be able to remove. How many total rolls of paper could the Elves remove if they keep repeating this process?
Starting with the same example as above, here is one way you could remove as many rolls of paper as possible, using highlighted @ to indicate that a roll of paper is about to be removed, and using x to indicate that a roll of paper was just removed:
```txt
Initial state:
..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.
Remove 13 rolls of paper:
..xx.xx@x.
x@@.@.@.@@
@@@@@.x.@@
@.@@@@..@.
x@.@@@@.@x
.@@@@@@@.@
.@.@.@.@@@
x.@@@.@@@@
.@@@@@@@@.
x.x.@@@.x.
Remove 12 rolls of paper:
.......x..
.@@.x.x.@x
x@@@@...@@
x.@@@@..x.
.@.@@@@.x.
.x@@@@@@.x
.x.@.@.@@@
..@@@.@@@@
.x@@@@@@@.
....@@@...
Remove 7 rolls of paper:
..........
.x@.....x.
.@@@@...xx
..@@@@....
.x.@@@@...
..@@@@@@..
...@.@.@@x
..@@@.@@@@
..x@@@@@@.
....@@@...
Remove 5 rolls of paper:
..........
..x.......
.x@@@.....
..@@@@....
...@@@@...
..x@@@@@..
...@.@.@@.
..x@@.@@@x
...@@@@@@.
....@@@...
Remove 2 rolls of paper:
..........
..........
..x@@.....
..@@@@....
...@@@@...
...@@@@@..
...@.@.@@.
...@@.@@@.
...@@@@@x.
....@@@...
Remove 1 roll of paper:
..........
..........
...@@.....
..x@@@....
...@@@@...
...@@@@@..
...@.@.@@.
...@@.@@@.
...@@@@@..
....@@@...
Remove 1 roll of paper:
..........
..........
...x@.....
...@@@....
...@@@@...
...@@@@@..
...@.@.@@.
...@@.@@@.
...@@@@@..
....@@@...
Remove 1 roll of paper:
..........
..........
....x.....
...@@@....
...@@@@...
...@@@@@..
...@.@.@@.
...@@.@@@.
...@@@@@..
....@@@...
Remove 1 roll of paper:
..........
..........
..........
...x@@....
...@@@@...
...@@@@@..
...@.@.@@.
...@@.@@@.
...@@@@@..
....@@@...
```
Stop once no more rolls of paper are accessible by a forklift. In this example, a total of 43 rolls of paper can be removed.
Start with your original diagram. How many rolls of paper in total can be removed by the Elves and their forklifts?

140
04/input/grid.txt Normal file
View file

@ -0,0 +1,140 @@
@@@@@@@@@.@@@@@@@@@.@.@..@@..@@.@.@@.@@.@@@@@@..@@..@.@.@@..@.@.@@@@@.@@.@@@@@@..@@@@@@@....@@@@@@@@.@.@.@@@@@@@@@@.@..@@@@@@@@@@@@@@@@.@.@@
@@@.@@@.@@@@@@..@..@@@@.@.@.@.@@@@.@.@@@@@@@..@@.@@.@.@@@@.@@@@@@.@@@@.@.@@@...@@.@@@@@@.@.@@@.@.@@@@@.@@@@@@@.@@.@@@@@@@@.@..@@@@.@@@@@@.@@
@@..@@.@@@.@@@@..@@..@..@@@@@@.@.@@..@@@@....@@@@@@.@.@@.@..@@@@@.@@@@.@@@@@..@@@.@@.@@.@@..@@@@@@@@.@@@@.@@@.@@@@@@@@@@.@@.@@@@.@@@..@@@.@@
@...@@.@...@@@@@@.@@..@@@@@@@.@...@@@@.@.@@...@@@.@@@@@@.@@@.@@@.@.@..@@@@@@@@.@.@@@@..@@@.....@.@@@@..@...@.@@@@@..@@@.@@@.@@....@.@@@...@.
..@@@@@.@.@@.@@@..@@@@@@.@@@.@@@@.@@@@.@...@@@@@...@.@@@..@..@..@.@.@.@@@@..@....@@@...@@@@@.@@.@@.@..@.@@@..@@@@@@@@..@.@.@@.@@@..@@@..@@@@
@@@.@@..@@.@@@..@@.....@@...@@@.@.@@@@@.@@@@..@.@@@@.@.@@@@@@.....@@.@@.@..@@@@@@@..@@.@@..@@@@.@@@.@..@@@.@@@@.@@@.@@@.@@@@@@..@@@@@@.@.@..
.@@@@.@.@..@.@@@@...@.@..@.@@@.@..@.@...@@@.@@..@..@...@@@..@@@@.@@@.@@@.@@@@.@.@...@@@@.@..@@@.@@..@.@.@@...@.@@.@.@@.@.@.@@@@.@@..@@@@.@@.
.@@@@@@@@@@@...@.@.@@@.@@.@.@.@.@@@@@@@.@@.@@@......@.@@.@@@.@@@@...@@@@@@@@@@@@@@@@.@@@.@@.@..@@.@@@@@..@@@@@@...@@@.@@@.@.@@@@.@@@@@@...@@
@..@.@@.@@@..@@@.@@.@@@@@@@@@@@@@@.@....@...@@.@@@..@@@@.@@@@@@@@@.@.@@..@@.@@@.@.@.@@@.@.@@@.@@@......@@@@...@@.@@@@.@.@@@.@.@@..@@@@.@.@@@
@@.@..@.@@@@@@@@.@.@@@@@.@.@.@@.@@@.@@@@@@@.@@@@@..@@@@.@@@@@@..@@@@@@..@.@.@@@.@@@@.@.@@.@@@.@@@@.@.@@...@@@@@@@.@@..@@@@.@@@.@@@.@@@@@..@@
@..@.@.@..@.@@.@@@.@..@@@@.@.....@..@@@@@..@@@..@@.@@@@@@.@@@....@@..@@@@@@@@@..@@@.@@..@@@.@.@@@@@.@@.@@@..@...@@.@@@..@.@.@.@@...@@.@@@.@.
.@@@.@@.@@@..@..@@.@.@@@@@@.@.@.@@@@.@@@@@@@@..@.@@@@@@@@.@@@@@@@@@@.@@.@@@...@@.@@@@@@@.@@@.@..@@.@....@@.@@...@@.@@..@.@..@@@@..@.@@@.@..@
.@.@@@.@@.@..@.@.@.@@.@.@@...@.@@.@..@.@..@.@@.@@.@@@@@.@@.@.@.@@@@@@@@@@@.@@@@@.@.@@.@@@.@.@@@@.@@@@.@..@.@@@@@.@@@@@.@.@@@.@@@.@@@@.@@.@@.
.@@..@.@@@@.@@@@@.@@@..@@@..@...@@@@@@.@.@.@.@@@@@@@.@@..@@@.....@@.@.@@@..@@@@..@@@..@.@@.@@@@@@.@@@...@...@@@@.@@@@@@@@@..@@@.@.@@.@@@@@..
.@..@@.@..@@@@@@@@@@@@.@@@@.@..@.@@@......@@@@@@.@.@..@@.@.@@.@.@...@.@.@@@@@@.@@@.@@@@@@..@.@.@...@..@@.@..@@@...@.@@@..@@...@@@@@@@@@..@..
@@.@...@@@@.@..@@.@@@.@@@.@.@.@.@.@.@.@@.@@@.@.@@@@@.@@@..@@..@..@@@@.@.@@@.@@.@.@@@@@@@@@.@.@.@.@@@@.@@@.@@@@.@@@.@..@.@@@@@@@.@@..@@@@..@@
@@.@@.@@.@@@@.@@@.@@@.@@@@...@@@@@@@@@.@@@.@@.......@@@..@@.@@@@@@@@...@@.@@@@@@@@@.@@@@@@@@.@.@@@@.@.@@@@@.@@@@@.@.@@@.@@@@@@@@@.@@.@.@@@.@
.@.@@@@@@@@@.@@@@..@.@.@.@@@@.@@@@@.@@....@.@.@.@@..@.@@@@@.@@@@@@@@.@.@@...@@@.@@@.@@@...@.@@@@@.@.@.@@@.@@@.@@@...@@.@@@....@.@@@@.@@@....
@.@@@.@@.@@@@@@@@@@.@@.@@@@@@@@@@@.@@@@@@@@@@@.@@@.@@.@..@.@@@@.@.@.@@.@..@@@@.@@@@@@@..@@@@@@@@.@.@.@@@@@.@.@@@@@..@..@.@.@@@.@@.@@@@..@@@@
.@...@@@@..@@@@...@@@@...@@@@.@...@.@@.@@@@@.@.@@@.@@@@@.@.@@@@@@....@@@@@@....@@@@.@.@@@@@@.@@@@@.@@.@..@.@@@@...@@@@@@.@..@@@@....@.@@.@@@
..@.@@@..@@@@.@@@@..@@.@@....@@@@.....@.@.@@@.@.@@@.@@@@@...@@@@@@.@@@@@..@@.@@..@@@.@..@.@....@@@.@.@.@.@@.@@@@@@@.@@@@@@@@.@.@.@@@..@..@.@
.@.@@@@@@@@@@@..@.@@@@.@@.@@@@..@...@..@@@.@.@@@@...@.@.@@..@.@@@@@@@@.@@.@.@..@@@.@.@@...@.@@@@..@.@@.....@.@@@@@.......@@@@@..@@@@@@@.@.@@
@@.@.@@@@@@@@@@@@.@@.@@@@@@.@@@.@.@.@@@@@@@.....@..@@.@@@@.@.@@@@@@.@@...@@.@@.@@@@.@.@....@...@.@.@@@@@@.....@@..@.@.@@.@@@@...@@@@@.@@@@@@
.@@@@..@@@@@@..@.@..@.@@.@...@@@@.@@@.@@.@@....@.@@@...@.@@....@.@@.@@@..@@@@.@@@@.@..@.@.@@@@.@@@@....@@.@@..@@@@@@.@@.@@.@..@@.@.@@@....@@
.@@.@@.@@@@@@@.@@@@@@.@@.@.@@@.@@..@.@@.@.@@@@@@.@@@.@@@@@@@@.@....@@@@@@..@...@.@.@@@@@@@.@.@@@@.@.@@@@.@@@....@@@@@@.@@@@@@@@@.@@@.@@@@@@.
@...@@@@@@.@@@.@..@@@.@.@@.@@.@@@@.@@@...@.@@@@@@@@@@@..@@@..@@..@@.@.@@.@@@@@@@.@@@@@.@@.@..@@.@@...@@@..@@@@....@@.@@@@@@@@@....@.@.@.@@.@
.@.@.@@@@@@@.@@.@.@@.@.@@@@.@@@..@@@@@@.@@@.@@.@@@@@.@..@@@@.@@@...@@@..@..@@..@.@@@@@@.@@@@@@.@@@@@.@@@@@..@@@.@@@@.@@.@@.@@@@@@@@@...@.@@@
@.@@@@@.@.@.@..@.@..@..@.@@@@@.@@@@@@@@@@.@@@@@@@.@.@@.@@@@@@..@@.@.@@@.@..@.@@@..@.@@@.@@@..@@@.@@@@@@.@@.@@.@.@@@@..@@@@@@@...@@@@@@...@@@
.@@@@@@.@@@.@@.@@@..@@.@@@@@@@.....@@@@.@@@@@@@@.....@.@@@.@@@@@@@..@.@@@@..@@.@....@.@.@.@@@@@@@@.@..@..@..@@@@..@@...@@@.@@@@..@@@@..@@@@.
@@.@@@@.@@@@@@.@@.@@.@@@@@@@@@@@.@@.@@..@@@@.@@@.@@.@@@@@.@.@@@@@@..@@@.@@@@@.@@.....@@@.@@.@@@@@@@@.@@@..@@..@@.@@.......@.@@@@...@@@@.@@..
@.@.....@@@...@@@.@@..@.@@@@@.@...@@.@@.@@@@@.@@..@@@@@@@@@@@.@@@.@@.@@@@..@...@@@..@@@.@.@.@.@.@@@@..@@....@.@..@.@@@.@..@....@.@@.@.@.@@@@
@@.@@@..@@@@@.@.@@.@@@@@@@@.@..@@@@..@@@@@@..@.@@.@@@@@@@@@@@@@..@@.@@@@.@@.@@.@@@.@@.@.@@@@@@@.@@.@@.@@@@@@@.@@....@@@...@@@@@@@@@..@@.@.@@
@..@..@@@.@..@@@@...@@.@.@...@.@@.@.@@.@.@.@.@@@@@.@.@@@@@@@@@@@..@@.@.@..@@.@@.@@.@.@.@@.@@.@@@.@@@..@..@@.@@.@@@@..@...@@@.@@@.@.@@@@@.@@@
@@@.@@.@.@.@@@@@.@@@....@@@@@@@.@@@@.@@..@@@@@@.@.@@.@.@.@@@.@.@@@@@.@@@...@@@.@.@@...@.@@.@@@@..@@@@.@.@..@@@@.@@.@@@@@@@@@@..@@@@.@@@.@@.@
@@.@@@..@@..@.@@@..@.@@@@@.@..@@@.@.@@.@@.@@@.@@@@@@.@@.@@.@@@@.@.@@@@@.@@@@.@@.@@@.@@..@@@@.....@@@@.@@@@@@@.@@@.@@.@@@@@..@@.@@...@@@@@@.@
@@@@.@.@@@@.@@.@@@@@..@.@@@@.@@.@.@@@@@@.@@.@@.@@.@@@.@@.@@@.@@@.@@@...@@@@..@@.@@@@@@@@@..@@@..@.@.@.@@..@@.@@@@.@@@.@.@@@..@@@.@@@@@@@@@.@
@@.@@..@@@.@@.....@...@@@.@@.@.@..@.@.@@@@@@.@.@@.@.@.@@.@.@@@@@@@@..@@@@.@@@.@.@@..@.@.@@@@@@@@@.@@@@@@.@.@..@@..@...@......@@@.@@.@@@@@@@.
@@@@..@...@@@@.@@@@@@@@.@@...@.@...@@@@.@@@@@@@@.@@@..@@.@@@@@.@@@@.@.....@@.@@.@.@..@.@@.@@@@@.@@@@@.@@@@@@@.@@@@..@@@@@@@@..@..@@.@@.@.@@@
.@@@@@@.@@.@@@@@@@.@@.@@.@.@@....@@.@.@@@@@@..@@@.@.@.....@.@@@@@@@@.@@@...@.@@.@.@@@@@.@...@@..@@.@@@@..@....@@@..@@@..@..@@@@@.@@....@@..@
@@@.....@.@@@@@@@@@.@@@@@@@@.@.@@.@@@...@@@.@@@.@@@@@@@.@@@.@..@@@@.@@@@@.@@@@.@@@@.@@.@@@@.@.@@@.@..@@@@.@@..@@.@.@.@@.@@..@@.....@@@@@@@.@
@@@...@.@@.@@@@..@@@@@.@@@@@@@...@@..@@@.@.@@@.@@..@@@@.@@@@.@@.@@..@@..@.@@@@.@@@..@@@@.@@@@.@@..@@..@.@@@.@..@@@@@@@.@.....@.@.@.@..@@@@@.
..@...@@.@@@@.@.@.@...@@..@@.@.@@.@@@.@@@@@@@@.@.@@...@.@@@@@@@@.@.@@@@@@@.@@@@..@@@@@@@@..@@@@@@.@@@...@@@@..@@.@@@..@.@@@@@@@.@@@..@@@@@@@
.@.@.@.@@@@@@@@.@@@@@..@@..@@...@.@.@@....@@...@@@....@@.@.@.@@.@@.@@.@...@@@...@..@.@.@.@.@@@.@@@.@@.@@@@@@.@...@.@@@@@@.@@.@.@@@@@@@@.@@@.
@@@..@@.@@@@@.@.@@@.@@@@..@....@..@@..@@@.@.@@@.@@...@@.@@.@.@@...@@@.@@.@@@@@.@.@.@@@.@@.@@@...@@.@....@@@.@@@.@@.@@@@.@@.@.@@@@@@.@@...@@@
@@@@.@.@@@@@@.@@.@@@@@@@@.@@@@@@@@@@.@@@@.@@@@.@@@.@.@@.@.@@..@@.@.@@.@@@..@@.@...@@.@@..@@@@.@@.@@....@@@...@@.@..@@@@@.@.@.@.@.@@.@@@.@@@@
@@@@@...@@@@.@.@@..@@@.@..@@@.@.@.@..@@@...@@.@@@..@@.@@..@.@@@..@@@..@@@@@...@@@@@.@@@...@@@@.@.@..@.@.@@.@@@...@@@@@.@@..@@..@@@.@@@@..@..
..@@@@..@@@@@@.......@@..@.@@.@@@...@@.@@@@@.@@@@.@...@@@@.@@.@@.@@@@.@@.@.@.@@@.....@@...@@@@.@@@..@@@.@.....@..@@@@...@@@@@@..@@@@@.@..@@@
@.@@@@@.@@...@.@@@@@@@@.@@@@@...@.@.@@@@..@.@@@.@@@.@@.@@.......@@.@@@@.@.@@@@@@@.@.@@..@@@@.@.@@.@@@@@..@@@.@.@...@.@@..@@@@@@.@.@@@...@@..
@@@..@......@.@@@...@@@@.@..@@@@@@.@@@..@@@@@@@@@@@@@.@@@@@@@@@.@.@..@.@@@..@.@.@.@@@@.@@@@..@@.@@..@..@@@@@@@@@@@@@@@@@@@.@@..@@.@@@@@@@@@.
.@@.@@@@@@@.@@.@@@@.@.@..@@@@@..@...@..@...@@@@@@@@@@....@...@@..@@@.@@.@@@@@@@.@@...@@@@.@@@@..@...@@@.@@.@.@@@@@@@.@.@.@@@@@@@..@.@..@@@..
@@@..@..@@.@.@@@.@@@.@@.@@@.@.@.@.@@.@@@@..@@.@.@@.@..@@@@@@.@@@..@@@@@@@@@.@@@@...@@@@@@.@@@@@.@...@@.....@.@.@@.@.@.@@@@@@@.@..@@@@.@.@@.@
@@@@@@@@....@..@.@@@@.@@@@.@@@@.@@@.@@@@.@@@@@@@.@@@@.@.@.@@@@@@..@@@@@..@@@@.@.@@@@@@.@.@.@@@....@...@.@.@.@@....@..@@@@@@@@@@@@@@@@@@.@@@@
@.@@@@@@@@@@...@@@.@.....@.@@@..@@.@.@@.@.@.@@@@@@@@@@@@.@@.@@@@...@.@.@@.@...@@@@..@@@@@@.@@@.@.@@@.@@.@.@@@@@@@@@.@@@...@@@@@@@@.@@@.@@@@@
@@@.@.@@@.@.@@@..@@@..@@@.....@.@.@@@@@..@@@..@@...@.@.@@.@.@@@..@..@@.@.@@..@@@..@@.@@@@..@..@@.@@@@@..@@@@@@.@@@@@@@@@.@@@@...@@..@@@@@@@.
.@.@@@@.@@@@@.@..@@@@....@@.@.@..@@@.@@.@.@.@.@@@@....@.@@@@...@@@@@@@...@@.@..@@.@@.@.@@.@.@@@@@.@.@....@@.@@@.@.@@...@.@@@@@@@.@@.@@@...@@
@@..@@@..@@@@.@@@@@..@.@@.@@@..@.@@@@@@@....@.@@@@.@@..@@...@..@@.@@@.@.@@@@.@@@@.@@..@@.@@@@...@@..@@@@@@@..@@.@@.@@...@@@@.@@@@.@@..@@@@.@
@..@@.@..@.@@@...@@@@.@..@@@.@.@@@@@.@@@.@@@@.@.@.@..@@..@@@.@@@@@...@@.@..@@@.@..@@.@.@@@@@@@@@@@@@@@.@@@@@...@@@.@@.@@.@@@@@@@.@..@.@@...@
@..@..@@@.@.@@@@.@...@@@..@.@@@@.@@@@.@@@.@@.@@@..@@@.@@@.@@@@@@.@.@@@@@@@.@@@..@@.@.@@..@@..@@@@.@.@@@.@@@.@@@..@..@@..@@@@@...@@@@....@@@.
@.@.@@@@.@@.@@@@@@@..@..@.@@@@.@.@..@@@@@..@...@@@..@@@.@.....@@...@..@.@@@.@@..@@.@.@@.@@@@@@@@@@.@.@@.@@@@......@.@.@.@@.@.@@.@@@@@@.@@..@
@.@.@.@@@@@@.@.@@@@.@@@@.@..@@@..@@@@@@@@@@.@@.@@@@..@.@......@.@.@@@@...@@@@@@..@.@@@@@@@@@@@..@.@@@@@.@@.@@@.@@@....@....@@@@@@@.@@.@@.@@@
@@@@@.@@.@..@@@@@@@.@@.@@@.@@.@@@@@@..@..@@@@@@@@@.@@@@@@@.@@@@..@@@@..@@..@@@.@@@..@.@@@..@@@.@.@@@@@@@..@@.@@.@@@.@@.@@@.@@@@@@@@@@@..@@@@
@@@@....@.@.@.@.@.@@@@@.@@..@@@@..@@@.@@@@@@@@@@...@@@..@@@@..@@@@@.@@@.@@.@@@@@.@..@....@.@.@@@...@@@@.@@@@@@.@@.@@@.@@....@.@@@@@@@@...@.@
@.@@.@...@.@@@@@..@@@@.@@@...@@@@@.@@@.@....@@.@@@..@..@@.@.@@@.@@@...@@@.@@..@.@@@.@@@@.@@..@..@.@..@...@@@@...@@@..@..@@@@..@@.@@..@@@@@.@
@@.@@.@@@@.@@@..@@@.@@.@@@.@.@...@@.@@@@.@@...@.@....@.@@@@.@..@@.@@@@@@@@@@@.@@..@@.@@@@@..@.@..@@@@@@@.@.@@.@@@@@@@...@@@@@..@@@@@@.@@@.@@
..@..@@@@@@@@..@@@.@...@.@@@.@@@....@@@@...@@@@@@.@.@@@.@@@@...@@@@...@@.@@.@.@@@@@@@.@..@.@@@@@.@@@@@@@@@@.@@@@@@.@..@@..@@@@@.@@@@@@.@.@@@
..@.@@@@@@..@@@@@.@.@@@..@.@@@@@.@@@.@..@@@@@@@.@@@@.@@@@@@@...@@@@..@.@@.@@@..@.@@@@@@...@@@@@..@..@@.@@@.@@@@@@@@..@@@@@@@@@.@..@.@@@..@.@
.@@@.@@@@@@.@@@@.@@@@@@.@.@@@.@.....@@.@@@@.@..@..@.@.@...@...@.@.@@..@@@@@@@.@@.@@.@.@@.@.@@@@@@@.@@@....@@.@@@@@@@.@@@@@@.....@..@@@.@@@.@
..@...@@.@@@@..@@@@@@@.@.@.@@@@@@@@..@.@@@.@@@.@@@.@@@@@@@..@@@...@@@.@@@..@.@.@@@@@@...@@@.....@@@@@@@..@@@@@@@@@@@..@@@@@..@@@@.@.@.@@@.@@
@.@..@@@.@@@@@@..@.@.@...@@@@@@@..@@@@@@@@@@@@@@..@@.@@.@@...@..@@.@@..@@...@@@...@@@@@@@@@@@@...@@@.@@@@@@@@@...@.@@@....@@@@@@.@@@.@@@@@@@
.@@@.@@@@@@.@@.@@..@@@@@@.@.@..@.@@.@@@@.@@@..@.@@@.@@@@.@@@@@..@@..@.....@.@@@@@@....@@@@@@@@..@@@@@..@..@@.@....@.@@@.@..@..@.@@...@@@@.@@
@@@.@.@@.@@.@..@.@.@@@@.@.@@...@@.@.@.@@@@@...@@@@.@@.@@@..@@.@@@.@@@.@...@@.@.@@.@@.@@...@@.@@..@@.@.@@@@@@@@.@@...@@@@@@@@@@@.@@..@@@@@@..
.@.@.@@..@.@.@@.@@@@@..@@.@@@@.@...@@@.@.@@.@@@.@@@@@@@@..@@..@@@.@@@..@.@@.@.@@@@@.@@@@@@..@@@@@@@@@@@@.@@@@.@@@.@@@.@@@.@@@@..@.@@@@.@@.@.
.@@@.@..@.@@..@@@.@@@@.....@@@@@@@@@@.@.@.@@@.@@@@@....@@@.@@@.@@...@@@.@@@..@.@@.@@@@@@.@...@@.@.@@@.@..@@@@@@..@@@@@..@.@.@..@@.@@@@@@@@@@
.@.@@@.@.@@@.@.@@.@@.@@..@.@@@.@..@@..@@@@@.@.@..@.@..@..@@.@@@.@@.@@...@@@@@@@.@.@@@.@@...@.@@..@.@.@@@@@@@@@@@@@@@@@@@.@.@@@@@..@..@@@@@@.
...@.@.@@.@@@@.@.@@......@.@.@..@@..@@@.@@@@....@@@.@...@.@@.@@@@@@@@@...@@..@.@.@.@@...@@.@@.@...@@.@..@@.@.@....@@..@@.@@@..@@.@.@@@..@@@@
@.@@@...@.@@@@.@@.@..@@@@..@@@@@@@@..@@@...@@@@@.@...@@@@@@@@@@...@@@@@@@@@@.@@@@@@@@@...@@.@@..@@.@@..@...@@@@@@@.@@..@.@.@.@.@@@.@.@.@.@@@
@@.@@.@@@@....@.@...@...@@@@@@@.@@@@@@@@@@@.@@@...@@@@@@@@@@@@@@@.@@..@.@@@.@@@.@@@@..@.@@@@..@@@@..@.@.@@.@@@@@@@.@@@@@@@@.@.@@@@@@@@@@.@@.
@@@@@..@@..@@@@@.@@@.@@@@@.@@@@@@@.@@@@@.@@..@@@.@.@@@@@.@.@@@..@@.@...@@@.@@..@.@.@@@.@.@@@@@@..@@@@.@@@@..@@..@@@.@@@@@.@.@...@@@@.@@...@@
@....@@@@@.@.@@@..@.@.@@.@..@.@@.@@@@.@@@...@@.@@@@..@.@.@.@@.@@.@@.@@@.@.@.....@@@@@.@.@@@..@..@.@.@@.....@@@@@....@..@@@@@@@@@@@@.@@.@@@.@
@@@@@@...@@@..@.@@.@..@.@@@@.@@@@@.@@@@..@@@@.@@@@@@..@..@@@@@@..@.@@@..@.@@.@@@@.@@.@@..@@@@..@..@.@@.@.@@.@@.@@@.@@@.@@@@@@@@....@@.@@.@@.
@@@@@@.@@@.@@@@@@@..@@..@@@.@@@@@@@@@@@@.@@@.@@.@.@@@.@@@.@@@@.@@@@@.@.@.@@@..@@@@@@@@..@@@@@.@@@@@.@@@..@@.@.@@@.@@@@..@@@.........@@@@@@@@
@@@..@.@@@@..@@@@@.@.@@@..@@.@..@@..@@..@.@@@.@@@.@.@.@..@@@.@.@@.@@.@...@@.@@@@.@.@.@@..@...@.@.@@@@...@@@....@@@.@@@@.@.@@@@@@.@@@@.@@@@.@
@@.@@@@@@@@..@.@.@@@@..@.@@@@@.@@@@@@@@@.@@@@@@.@@@@.@@@@@@.@@@@..@@@...@@@.@@@@.@@.@@..@@@@.@.@.@.@@@@@@...@@@.@...@.@.@.@@@@@@@@@@.@@@@@@@
@@@@@.@@..@@.@@.@@@@@@@@.@@@@@...@..@@@@.@@..@.@..@@@..@@.@@@@.@.@@.@.@@@@.@@@@@.@..@@.@@.@@@.@@@@.@@@@..@@@@..@@@@@.@@..@.@@@@@@.@..@@@.@@@
@.@@...@..@@@@@@@.@@..@..@.@@.@@..@...@..@.@.@.@.@@@@..@@@.@.@@@.@..@...@.@@@.@@@@..@@.@@@@@.@@..@@@@.@.@@@....@@@@.@..@.@@@.@.@@..@.@@..@@@
@@@.@@@..@@@@.@..@@@..@@.@@@@@....@.@@@@...@@@@@@..@.@@@..@@@@@@@.@@.@.@@...@.@@@.@..@@..@.....@@@@..@@.@@@@@.@..@.@@@@@@@@..@@@..@@@.@@..@@
.@@@..@.@@.@.@@@@.@@..@.@@@@@@@@.@@.@@@@@@@.@@@...@.@.@@.@.@.@@@@@@@@@..@@@@@..@@...@.@.@@.@@@@@..@@.@..@.......@@@@@....@.@.@@@@.@@..@@@.@.
.@..@@.@@@..@@@.@@@@@@.@.@...@@@@@@..@@.@@@@@@@@.@.@@@@@@@@..@@@@.@@..@@@@@@@@.@@@..@@@@.@.@@.@.@@@.@@@..@@@..@.@@.@..@@@.@@@.@.@@...@.@@.@.
@@@@.@@@@@.@@@.@.@@@.@.@....@..@.@@@@@.@..@@@@...@.@.@@@@..@@.@@@.@@..@@@..@@@.@...@@.@@@@@.@@@.@.@@@.@...@.@..@.@..@@@@@.@@@@@@@@.@@.@@.@..
..@@@..@@@@@@@@@@@@..@@@@.@@@.@@.@@@..@@@.@.@@@@@.@.@@@@.@@@@.@.@@@@@@@@@.@@@.@@..@@@@@..@.@@.@.@@@..@.@.@@..@.@.@@@..@......@@@@.@@@@.@.@@@
@@@@.@..@.@...@.@.@@@@@.@@@..@@@@.@@@..@@@@.@...@@..@@@..@.@@.@@@@@@.@@@.@@@@@@...@@.@@@..@.@@.@.@.@@@@.@@.@@@@.@@@@@@.@@@@@@@@@..@@..@.@.@@
.@.@@@@..@.@.@@@.@..@@@.@.@@@@.@.@.@@..@.@@@@..@...@@@@@@@@@.@@..@.@@@@@@@@.@@..@.@@@.@.@.@@@.@@@@@.@.@@@@@@..@.@.@.@@@@@@.@@.@@@@@.@@.@.@@@
@..@@@@@@@.@@@@@.@.@@@@.@@@..@@.@@@...@..@@@@@.@@.@@@@@..@.@@.@..@@@..@@..@@@@@@@@@.@@@@@..@@@@@@@@@.@..@@.@...@@@.@..@@.@...@@@.@@@.....@@@
...@@@@@@@.@.@@@.@.@@.@@@.@@@@@..@@@@@@@@..@..@.@.@@@.@@@@...@.@@..@..@.@@.@...@@.@@.@.@@@@....@..@@@@@@@@...@@.@.@.@@@@@..@@@@@@.@..@@@.@@@
.@@@.@.@@....@@@..@@@@@@@..@...@@.@@@@.@@@@@.@@.@..@@@..@@.@@@@@.@..@@@..@@@@@@@.@.@@...@@@..@@@@@@..@@@@..@@.@@..@.@@..@@.@@@@.@@@@@@@@@@@@
....@@.@@@.@.@@...@..@.@@@.@...@@@@.@.@@@@@.@@@@...@@..@@.@@@.@..@@....@..@@@@@.@@@.@@@..@.@...@...@.@@@@.@..@@.@.@@@..@.@@@@@@@@@@.@@@@...@
.@@@...@.@@@@....@..@@@@@@@@@@@@.@@@.@@@@@@@@@@@...@.@@.@@.@@.@..@@@@.@@@@@@@.@@@..@@@.@@@@@.@@@..@.@@.@.@.@@@@@@.@@@@@@@.@.@..@@@@@.@@.@@..
.@@@@@@@.@@..@..@@@@@@@@@.@.@@@@@.@@@@.@@@..@@.@@..@@.@@@@..@@@@@@@.@.@@@@@@.@@.@@@@@@@@@@@@@@.@@.@@@@@@@@@@...@..@@...@@@@..@@.@..@..@@@@@.
.@@@@.@@.@@..@@@.@@.@.@@@.@.@.@@....@@@..@@.@@@@@@@@@@.@@@@@.@.@@@...@@@@@@@@....@@.@@@.@....@@@@@.@@@@.@@@..@@...@...@.@@@..@@@.@@@@@@@@@..
@.@@@..@@.@@@..@@.@.@.@..@@@@@@@@@@@@..@.@@.@@@@@@@.@@@@@@@@..@.@@.@.@@@..@@@..@.@@@@@@..@@.@@.@@@@.@@@...@@@@...@.@..@@.@@@.@.@@@@@@@.@@@@.
..@@@@.@@.@.@.@@@.@@@..@..@@@@@@..@.@@@.@@.@.@@@@@.@@.@@@@@...@.@.@@.@.@@@@@.@@@@@@@@@@@@...@.@.@@@..@.@@@@@@..@.@..@@@.@..@.@.@@@.@.@@@....
..@@@.@..@@@.@@@..@@.@.@@@@.@@.@@@@@@@@@@.@@@@.@@.@@@@@.@..@...@@..@@@....@@@.@.@..@@@@@.@..@@..@@.@.@@@@..@@@@@.@.@..@@.@@.@@.@@@@..@@@.@@.
@@.@@.@.@@@@@@@@@.@@.@...@@@@@..@@@@.@.@@@@@@@@.@@@.@@.@...@@..@@@@@.@..@@@@.@@@.@..@@@@@..@@@@@.@@@.@@.@@@@.@@@@@@@.@@.@@.@.@..@.@@..@@@@@@
@.@@..@.@@.@..@@@@@@@.@@.@@.@@@.@.@.@@@...@.@...@.@...@.@@@@@..@.@@@@@@@.@.@.@@..@.@.@@.....@.@@@@@@@@@@@@@.@@.@.@..@.@...@@@..@@@@.@@@@@...
@@@@@@@@@@@@@@.@.@@@@@.@.@@@@@@@@.@@.@.@@@.@@@@@@@..@@@@.@@@@.@@@@.@@.@@@@.@@@@@@@@.@@@@@@@.@@.@.@..@@.@.@@..@..@.@@@.@.@@.@@.@.@.@@.@@@.@@@
@..@...@..@@@@@.@.@@@@@@@@@...@@@.@@@.@@.@@@@@@@.@..@@@.@@.@..@@@@.@@.@@@...@@@@@@@.@.@.@@.@@....@@....@.@@.@@@@..@@@@@@..@..@@@.@.@@@@@@.@.
@.@.@..@..@@..@@@.@..@@...@@@@@@@.@@.@.@..@..@....@@.@@.@..@@@...@@@@@@.@@@@@@.@@.@.....@@..@.@.@.@@@.@@.@.@@..@@@.@@@@@..@@@..@@.@..@..@@@.
@@@@..@.@.@@.@..@@@@@@@..@.@@@.@@.@..@...@@@@@.@.@@@@@..@@.@@@@@@@.@@@@@.....@.@.@..@.@@..@..@@@@@@.@.@..@..@@@@@.@.@@@@.@@@@@..@@.@.@..@.@@
@@..@@@@@@@@@@@@@....@..@@@@@@@.@@@@@@.@@@@.@.@@@@@@@@@@@..@@@@..@.@.@..@@@@..@@.@..@.@@@@@....@@@@@...@@@.@@@...@.@.@.@@@.@.@@@.@.@.@@@.@.@
@@@@.@.@@@...@..@.@..@@@@@@@@@.@.@@..@.@@@..@@@@@@@.@.@.@@@@.@...@@@@@@@@..@.@....@@.@@..@@...@@.@@.@@@.@.@..@.@@..@..@@.@@..@@@@@@@@@.@@@@@
@@.@.@..@@@.@@.@..@.@.@@@@@@@@..@@.@@.@.@@.@.......@.@@...@..@..@.@@.@@@..@@..@..@@@@@@@..@@.@@.@.@@...@@@@@@.@@@@@@.@..@..@@@.@@@.@@.@@@@..
@@@...@....@.@.@.@.@.@@....@@@@@.@@@...@@@@@@.@@@..@@.@@..@.@@.@@@@.....@..@@@.@..@.@@.@@.@@@.@@@.@@@@@@.@@@@@@.@..@@@.@@..@@.@@@@@@@@@..@@@
@@.@@.@.@@@@@.@@.....@@@.@@@@..@@..@.@...@@@..@@.@@@.@@.@@@.@.@@.@.@..@..@@@@@.@.@@@@.@..@.@@.@@..@.@@@@@@@..@@@..@.@@@...@@@..@@@@@......@.
.@@..@@@@@@@.@.@@@@@@@@..@@@@@@@..@.@@@....@@@..@..@@@..@.@.@.@@@@@.....@@.@@@@@..@@@@..@.....@..@@@@.@@@.@@@.@@@@.@@@@.@.@..@.@.@...@@.@.@@
@.@@@.@.@@@@....@.@@@..@@..@@.@@@@@.....@@.@@@@@@@..@@@@@.@.@..@@@@@@@....@.@.@@@@@@.@@@@@@@.@@.@.@@@.@@@@@@@@@.@@@@.@@@.@@@.@@.@.@@.@@.@...
.@@.@.@@@@@.@@....@@@.@@@@@@.@@@.@.@@..@@@.@.@..@.@...@.@@@..@.@......@@@@@@@@@@@.@.@.@.@@@.@.@@....@@@..@@@.@@@@@@@...@@@@@.@@@@@@.@......@
.@@.@@....@..@@@@.@@@.@.@.@.@@.@@@.@@@.@@@.@@...@@.@@@@@.@@@@..@@.@..@@@@@@@@@.@@@@@@@.@..@@@.@.@@...@@@@@@@.@@@@@@@@.@.@@@.@@@@@@.@@@@.@@@@
..@@@@.@.@@...@@..@@@...@@.@@@@@@@@@@@.@@@..@@@.@@.....@@...@@@.@@.@..@..@@.@.@@@.@.@@@.@.@@@@@.@@.@@@..@@@@@@@@@@..@.@@@@@@@@.@@.@@@@..@@@.
.@@.@@@@@@..@@@@@.@.@@@@@@@.@@@@..@@.@.@@...@@@...@..@@....@@.@.@@@.@.@@@..@@@.@@...@.@.@@..@@..@@.@@@@@@@@@.@@.@@@@@@@@@@..@.@@@.@.@@@.@@@.
@.@@.@..@......@@@@@.@@.@@.@@@@@@@@.@.@@.@.@@..@...@...@.@@@.@@@.@@@@@.@..@.@@@@@@@.@@@@@@..@@@@..@@@.@.@@@@..@..@@@@@..@@.@@.@@..@..@@.@@..
@@.@@.@@@@@@.....@@@.@.@@.@@@@.@.@@..@.@.@@.@@@.@..@.@@.@@@@.@@@@@..@@..@@@...@.@.@@@@..@@@...@@@.@@@@@.@..@@@@@@@@@..@@.@@@@@.@@@@@@..@@.@.
....@@@@.@....@@@@@@@@..@@@@@@.@..@@@@..@.@@@@..@.@@@@@@@@.@@@@@@@@@@.@@@@@@@@@@@.@.@@@.@.@@.@@.@@@@.@...@@.@@@@@@@@.@@.@.@@..@@@.@.@.@.@.@@
.@.@.@.@.@@@@@@.@@..@@...@.@@.@@@.@@.@@@.@.@@.@@.@.@@@.@..@@.@......@@@@@...@..@@@@@@@@@.@@@@@@@@@@....@@@@.@...@@@.@@@@.@.@@@@@.@@@...@.@@@
@@.@@.@@@@.@@@@.@..@......@@@.@.@...@@.@@@.@@@@@@@@@@@@@..@@@.@.@...@@@@@.@@.@@@@..@.@@@.@.@@.@@@@.@..@.@@@@.@@..@@.@..@@@.@@@@@.@@...@@@.@.
.@@@@.@@@.@@@@@@@@@@@@@@.@@@@@@@@..@.@@@@@@@.@@.@@@.@.@@.@@@.@@@@@@.@@@@.@@.@@@@.@.@@.@@@..@@@.@.@@@....@@.@..@@@.@.@@@..@@@@.@@..@.@.@@@@.@
@@@..@@@@.@@..@@@@@@@@@..@@.@.@.@@@@@@.@@.@@.@@.@.@@@@@.@@..@.@@@.@.@@@@.@@....@@@@.@...@@.@..@@..@..@@@@@@@@.@.@@@.@@.@..@.@..@.@.@@@...@.@
@.@@@..@..@@@.@@@@@@.@@@@@@@.@.@.@.@@@..@.@@@.@@@@..@..@@.@.@@@@@.@.@@.@.@..@@.@@@@@@.@.@.@@.@@@@@@@.@@@..@@...@@@..@@.@@@.@@@@@@..@@.@@.@@@
.@@@@@.@@@...@@@@.@..@@@..@@..@.@@@@..@........@@@.@@.@@.@.@@@.@@@@...@@@@@@..@@@.@.@...@@.@@.@@.@@@...@.@@@.@@.@.@@.@..@@..@.@@@@@@@@...@@.
@@@...@@@@@@@@@@....@@@@@.@.@.@..@..@.@@...@.@.@..@@@@.@.....@@.@..@..@...@@@@.@@.@@@@@@@.@@.@@.@@@@.@@@@@.@@.@@.@@@@@.@@@...@@@@@.......@..
@@@..@..@@@@@...@@@@@@@@.@@.@@@@@.@@.@@.@@@@...@.@@@@@@@@@@@@@@@..@.@@..@@@.@....@@.@@@@@.@@@.@@@@@..@@@@.@@@@.@@.@....@@@@..@@@@@@@@@@.@..@
@@.@@@@@@@..@@.@@@@..@@@@.@@@@@.@@.@@.@@@@@@@.@@@@@.@.@...@@@..@.@@..@@@@@..@@@@@.@@@@.@@@@.@.@@.@@@@@@.@@@@.@@.@..@.@@@..@.@@@.@@.@@@@.@.@@
..@@..@.@@@@@@.@@.@@@@@@@@@.@..@.@.@@..@.@@@@@@@@@@@@.....@.@..@@@...@@@.@@..@@.@@@.@.@@@@@@.@@@....@@.@@..@@.@@@@@.@@..@@.@@@@@@..@@@.@@..@
@@..@.@.@.@@.@@.@@@@@.@..@@...@.@@@..@@..@@@.@@@..@@.@@@@@@@....@.@@@@@@..@@.@@.@@..@.@@@@@@...@@@@.@@@....@@@..@@..@@..@.@@.@....@@.@.@@@@.
@...@@.@@@.@.@@@.@.@@@@@@@...@@.@@.@@@..@@@@.@@@.@@@.@.@.@@@@@@.@..@@@@@@@@@@.@@.@.@@.@.@.@@@.@@.@@@..@.@@@.@.@.@@@@..@...@..@@@@.@..@.@.@@.
..@@@@...@@@.@@.@.@@@@@@@..@@@.@.@@@@@.@@@@@@@@@.@..@@@@@@.@@@.@...@@.@@@@@@@@.@.@.@..@@@@@..@@@.@.@.@@.@@...@.@@....@@@@@.@@@@.@..@..@@@@.@
.@@.@@...@.@.@..@.@@@@.@@@.@.@.@.@@@..@@@.@@@@@@@@@@@.@.@@@@@.@@@.@.@@.@.@.@.@@.@@@@.@@@.@@@@..@@@@@@@@@@@...@@@@@.@@@@...@...@@.@@.@@.@@.@@
.@...@@@@.@@@.@@..@@@@@@@.@......@@.@..@@@@@@.@@@@.@@@.@@@@..@@...@.@@@@@@@.@.@@..@@.@..@@.@@@@@@..@@@@@@@@@@@@@@...@.@.@@@@@.@@@.@@.@@@..@@
@@.@@.@.@@.@@.@.@@..@@.@@..@...@.@@@@.@@@..@@@@.@@@@@@@@..@@@.@@.@..@@@@.@@@.@..@@@@@@@@@@@..@@@.@...@@..@..@@@@.@@@@@.@@@@@@...@@.@.@.@@.@@
@@.@@@.@@@@@@.@.@@@@@@@.@@@@@@@@@..@@.@..@@@@.@..@.@@.@@@.@.@.@.@@@@.@.@.@.@.@@.@.@.@@@@@@@@@@@..@@......@@@.@@.@@@@@@@@@@@..@..@..@@@@@@@@@
@@@@.@@.@@@.@.@.@@@@..@@@@@@@@@..@..@.@@@.@@@@@..@@@@@.@@@@@..@@@@.@@.@...@@...@@.@..@..@@@...@..@...@@.@@@.@@.@..@@..@@@@@@@@@@@@.@@@@.@@@.

10
04/input/test_grid.txt Normal file
View file

@ -0,0 +1,10 @@
..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.

87
04/main.py Executable file
View file

@ -0,0 +1,87 @@
#!/bin/python
from logging import debug, DEBUG, basicConfig
from sys import argv
def parse_input(input_filepath: str) -> list[str]:
grid: list[str] = []
with open(file=input_filepath, mode="r") as input_file:
input_data: list[str] = input_file.readlines()
debug(f"\n\nRAW INPUT: {input_data}\n\n")
for line in input_data:
grid.append(line.strip())
return grid
def is_accessessible(grid: list[str], row: int, col: int) -> bool:
if grid[row][col] != "@":
return False
count = 0
adjacent_spots = [[""] * 3] * 3
for x_offset in range(-1, 2):
for y_offset in range(-1, 2):
if (
row + x_offset < 0
or row + x_offset > len(grid) - 1
or col + y_offset < 0
or col + y_offset > len(grid[0]) - 1
):
continue
adjacent_spots[x_offset + 1][y_offset + 1] = grid[row + x_offset][
col + y_offset
]
if grid[row + x_offset][col + y_offset] == "@":
count += 1
return count < 5
def get_accessible_paper_rolls(grid: list[str]) -> list[tuple[int, int, str]]:
accessible_paper_rolls: list[tuple[int, int, str]] = []
for row in range(len(grid)):
for col in range(len(grid[row])):
if is_accessessible(grid, row, col):
accessible_paper_rolls.append((row, col, grid[row][col]))
return accessible_paper_rolls
def remove_accessible_paper_rolls(
current_grid: list[str], paper_rolls: list[tuple[int, int, str]]
) -> list[str]:
for paper_roll in paper_rolls:
current_grid[paper_roll[0]] = (
current_grid[paper_roll[0]][: paper_roll[1]]
+ "x"
+ current_grid[paper_roll[0]][(paper_roll[1] + 1):]
)
debug("GRID AFTER REMOVALS:")
for row in current_grid:
debug(f"{row}")
return current_grid
def main() -> None:
input_filepath = "input/test_grid.txt"
input_grid = parse_input(input_filepath)
paper_rolls = get_accessible_paper_rolls(input_grid)
count = len([x[2] for x in paper_rolls])
print(f"Paper rolls initially accessible by the forklift: {count}")
current_grid = input_grid
remove_accessible_paper_rolls(current_grid, paper_rolls)
while len(paper_rolls) > 0:
paper_rolls = get_accessible_paper_rolls(current_grid)
count += len([x[2] for x in paper_rolls])
current_grid = remove_accessible_paper_rolls(current_grid, paper_rolls)
print(f"Total paper rolls accessible by the forklift: {count}")
return
if __name__ == "__main__":
if "-d" in argv or "--debug" in argv:
basicConfig(filename="debug.log", level=DEBUG)
main()
exit(0)

36
05/Makefile Normal file
View file

@ -0,0 +1,36 @@
# Compiler
CXX = g++
# Compiler flags
CXXFLAGS = -Wall -g
# Target executable
TARGET = ./main
# For deleting the target
TARGET_DEL = ./main
# Source files
SRCS = src/main.cpp src/produce_database.cpp src/read_input.cpp src/merge_sort.cpp
# Object files
OBJS = $(SRCS:.cpp=.o)
# Default rule to build and run the executable
all: $(TARGET) run
# Rule to link object files into the target executable
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJS)
# Rule to compile .cpp files into .o files
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
# Rule to run the executable
run: $(TARGET)
$(TARGET)
# Clean rule to remove generated files
clean:
rm $(TARGET_DEL) $(OBJS)

55
05/README.md Normal file
View file

@ -0,0 +1,55 @@
# --- Day 5: Cafeteria ---
As the forklifts break through the wall, the Elves are delighted to discover that there was a cafeteria on the other side after all.
You can hear a commotion coming from the kitchen. "At this rate, we won't have any time left to put the wreaths up in the dining hall!" Resolute in your quest, you investigate.
"If only we hadn't switched to the new inventory management system right before Christmas!" another Elf exclaims. You ask what's going on.
The Elves in the kitchen explain the situation: because of their complicated new inventory management system, they can't figure out which of their ingredients are fresh and which are spoiled. When you ask how it works, they give you a copy of their database (your puzzle input).
The database operates on ingredient IDs. It consists of a list of fresh ingredient ID ranges, a blank line, and a list of available ingredient IDs. For example:
3-5
10-14
16-20
12-18
1
5
8
11
17
32
The fresh ID ranges are inclusive: the range 3-5 means that ingredient IDs 3, 4, and 5 are all fresh. The ranges can also overlap; an ingredient ID is fresh if it is in any range.
The Elves are trying to determine which of the available ingredient IDs are fresh. In this example, this is done as follows:
Ingredient ID 1 is spoiled because it does not fall into any range.
Ingredient ID 5 is fresh because it falls into range 3-5.
Ingredient ID 8 is spoiled.
Ingredient ID 11 is fresh because it falls into range 10-14.
Ingredient ID 17 is fresh because it falls into range 16-20 as well as range 12-18.
Ingredient ID 32 is spoiled.
So, in this example, 3 of the available ingredient IDs are fresh.
Process the database file from the new inventory management system. How many of the available ingredient IDs are fresh?
## --- Part Two ---
The Elves start bringing their spoiled inventory to the trash chute at the back of the kitchen.
So that they can stop bugging you when they get new inventory, the Elves would like to know all of the IDs that the fresh ingredient ID ranges consider to be fresh. An ingredient ID is still considered fresh if it is in any range.
Now, the second section of the database (the available ingredient IDs) is irrelevant. Here are the fresh ingredient ID ranges from the above example:
3-5
10-14
16-20
12-18
The ingredient IDs that these ranges consider to be fresh are 3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, and 20. So, in this example, the fresh ingredient ID ranges consider a total of 14 ingredient IDs to be fresh.
Process the database file again. How many ingredient IDs are considered to be fresh according to the fresh ingredient ID ranges?

1168
05/input/ingredients.txt Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,11 @@
3-5
10-14
16-20
12-18
1
5
8
11
17
32

81
05/main.py Executable file
View file

@ -0,0 +1,81 @@
#!/bin/python
from logging import debug, DEBUG, basicConfig
from sys import argv
def parse_input(input_filepath: str) -> tuple[list[tuple[int, int]], list[int]]:
output: tuple[list[tuple[int, int]], list[int]] = ([], [])
with open(file=input_filepath, mode="r") as input_file:
input_data: list[str] = input_file.readlines()
debug(f"\n\nRAW INPUT: {input_data}\n\n")
ingredient_id = False
for line in input_data:
if line.strip() == "":
ingredient_id = True
continue
if ingredient_id:
output[1].append(int(line.strip()))
continue
output[0].append(
(int(line.strip().split("-")[0]), int(line.strip().split("-")[1]))
)
return output
def find_available_fresh_ids(
fresh_id_ranges: list[tuple[int, int]], available_ids: list[int]
) -> int:
available_fresh_ids = 0
for id in available_ids:
for id_range in fresh_id_ranges:
if id >= id_range[0] and id <= id_range[1]:
available_fresh_ids += 1
break
return available_fresh_ids
def condense_id_ranges(id_ranges: list[tuple[int, int]]) -> list[tuple[int, int]]:
id_ranges.sort(key=lambda id: id[0])
debug(f"SORTED ID RANGES: {id_ranges}")
condensed_ranges: list[tuple[int, int]] = []
temp_range: tuple[int, int] = id_ranges[0]
for i in range(1, len(id_ranges)):
if temp_range[1] > id_ranges[i][1]:
continue
if temp_range[1] < id_ranges[i][0]:
condensed_ranges.append(temp_range)
temp_range = id_ranges[i]
continue
temp_range = (temp_range[0], id_ranges[i][1])
condensed_ranges.append(temp_range)
return condensed_ranges
def main() -> None:
input_filepath = "input/ingredients.txt"
input_fresh_ranges, input_available_ids = parse_input(input_filepath)
debug(f"INPUT RANGES: {input_fresh_ranges}")
debug(f"INPUT AVAILABLE IDS: {input_available_ids}")
available_fresh_ids = find_available_fresh_ids(
input_fresh_ranges, input_available_ids
)
print(f"There are {available_fresh_ids} available fresh ingedients.")
condensed_id_ranges = condense_id_ranges(input_fresh_ranges)
debug(f"CONDENSESD RANGES: {condensed_id_ranges}")
sum_of_id_ranges = sum([x[1] - x[0] + 1 for x in condensed_id_ranges])
print(f"There are {sum_of_id_ranges} total fresh ingredient IDs.")
return
if __name__ == "__main__":
if "-d" in argv or "--debug" in argv:
basicConfig(filename="debug.log", level=DEBUG)
main()
exit(0)

22
05/src/main.cpp Normal file
View file

@ -0,0 +1,22 @@
/* Filename: main.cpp
* Author: Alice Winters
* Created: 05/12/2025
*/
#include "produce_database.h"
const std::string INPUT_FILEPATH = "input/ingredients.txt";
int main()
{
produce_database produce_db(INPUT_FILEPATH);
// produce_db.debug_fresh_ranges();
// produce_db.debug_available_ids();
produce_db.union_ranges();
// produce_db.debug_fresh_ranges();
int64_t available_fresh_ingredients = produce_db.get_available_fresh_ids();
std::cout << "Available fresh ingredients: " << available_fresh_ingredients << std::endl;
int64_t fresh_ingedients = produce_db.get_fresh_ids();
std::cout << "Total fresh ingredients: " << fresh_ingedients << std::endl;
return 0;
}

77
05/src/merge_sort.cpp Normal file
View file

@ -0,0 +1,77 @@
// Credit: https://www.geeksforgeeks.org/cpp/cpp-program-for-merge-sort/
// C++ program for the implementation of merge sort
#include "merge_sort.h"
using namespace std;
// Merges two subarrays of vec.
// First subarray is vec[left..mid]
// Second subarray is vec[mid+1..right]
void merge(vector<tuple<int64_t, int64_t>> &vec, int left, int mid, int right)
{
int i, j, k;
int n1 = mid - left + 1;
int n2 = right - mid;
// Create temporary vectors
vector<tuple<int64_t, int64_t>> leftVec(n1), rightVec(n2);
// Copy data to temporary vectors
for (i = 0; i < n1; i++)
leftVec[i] = vec[left + i];
for (j = 0; j < n2; j++)
rightVec[j] = vec[mid + 1 + j];
// Merge the temporary vectors back into vec[left..right]
i = 0;
j = 0;
k = left;
while (i < n1 && j < n2)
{
if (get<0>(leftVec[i]) <= get<0>(rightVec[j]))
{
vec[k] = leftVec[i];
i++;
}
else
{
vec[k] = rightVec[j];
j++;
}
k++;
}
// Copy the remaining elements of leftVec[], if any
while (i < n1)
{
vec[k] = leftVec[i];
i++;
k++;
}
// Copy the remaining elements of rightVec[], if any
while (j < n2)
{
vec[k] = rightVec[j];
j++;
k++;
}
}
// The subarray to be sorted is in the index range [left..right]
void mergeSort(vector<tuple<int64_t, int64_t>> &vec, int left, int right)
{
if (left < right)
{
// Calculate the midpoint
int mid = left + (right - left) / 2;
// Sort first and second halves
mergeSort(vec, left, mid);
mergeSort(vec, mid + 1, right);
// Merge the sorted halves
merge(vec, left, mid, right);
}
}

13
05/src/merge_sort.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef MERGE_SORT_H
#define MERGE_SORT_H
#include <iostream>
#include <vector>
#include <tuple>
#include <stdint.h>
void merge(std::vector<std::tuple<int64_t, int64_t>> &vec, int left, int mid, int right);
void mergeSort(std::vector<std::tuple<int64_t, int64_t>> &vec, int left, int right);
#endif

136
05/src/produce_database.cpp Normal file
View file

@ -0,0 +1,136 @@
#include "produce_database.h"
#include "read_input.h"
#include "merge_sort.h"
void produce_database::parse_input(std::vector<std::string> input_ranges, std::vector<std::string> input_ids)
{
std::string temp_string;
std::tuple<int64_t, int64_t> temp_tuple;
for (int i = 0; i < (int)input_ranges.size(); i++)
{
temp_string = "";
for (int j = 0; j < (int)input_ranges[i].size(); j++)
{
if (input_ranges[i][j] == '-')
{
std::get<0>(temp_tuple) = std::stoll(temp_string);
temp_string = "";
continue;
}
temp_string.push_back(input_ranges[i][j]);
}
std::get<1>(temp_tuple) = std::stoll(temp_string);
this->fresh_ingredient_id_ranges.push_back(temp_tuple);
}
for (int i = 0; i < (int)input_ids.size(); i++)
{
this->available_ingredient_ids.push_back(std::stoll(input_ids[i]));
}
return;
}
produce_database::produce_database(std::string filename)
{
std::tuple<std::vector<std::string>, std::vector<std::string>> input = read_input_from_file(filename);
this->parse_input(std::get<0>(input), std::get<1>(input));
}
int produce_database::get_fresh_ranges_size()
{
return this->fresh_ingredient_id_ranges.size();
}
std::tuple<int64_t, int64_t> produce_database::get_fresh_range_from_index(int index)
{
return this->fresh_ingredient_id_ranges[index];
}
int produce_database::get_available_ids_size()
{
return this->available_ingredient_ids.size();
}
int64_t produce_database::get_available_id_from_index(int index)
{
return this->available_ingredient_ids[index];
}
void produce_database::debug_fresh_ranges()
{
for (int i = 0; i < (int)this->get_fresh_ranges_size(); i++)
{
std::cout << std::get<0>(this->get_fresh_range_from_index(i));
std::cout << "-";
std::cout << std::get<1>(this->get_fresh_range_from_index(i));
std::cout << std::endl;
}
}
void produce_database::debug_available_ids()
{
for (int i = 0; i < (int)this->get_available_ids_size(); i++)
{
std::cout << this->get_available_id_from_index(i) << std::endl;
}
}
void produce_database::union_ranges()
{
mergeSort(this->fresh_ingredient_id_ranges, 0, (int)this->fresh_ingredient_id_ranges.size() - 1);
std::tuple<int64_t, int64_t> temp_tuple = this->fresh_ingredient_id_ranges[0];
std::vector<std::tuple<int64_t, int64_t>> unioned_ranges;
for (int i = 1; i < (int)this->get_fresh_ranges_size(); i++)
{
if (std::get<1>(temp_tuple) > std::get<1>(this->fresh_ingredient_id_ranges[i]))
{
continue;
}
if (std::get<1>(temp_tuple) < std::get<0>(this->fresh_ingredient_id_ranges[i]))
{
std::cout << std::get<0>(temp_tuple) << "-" << std::get<1>(temp_tuple) << std::endl;
unioned_ranges.push_back(temp_tuple);
temp_tuple = this->fresh_ingredient_id_ranges[i];
continue;
}
std::get<1>(temp_tuple) = std::get<1>(this->fresh_ingredient_id_ranges[i]);
}
unioned_ranges.push_back(temp_tuple);
this->fresh_ingredient_id_ranges = unioned_ranges;
return;
}
int64_t produce_database::get_available_fresh_ids()
{
int count = 0;
for (int i = 0; i < (int)this->available_ingredient_ids.size(); i++)
{
for (int j = 0; j < (int)this->fresh_ingredient_id_ranges.size(); j++)
{
if (this->available_ingredient_ids[i] >= std::get<0>(this->fresh_ingredient_id_ranges[j]) && this->available_ingredient_ids[i] <= std::get<1>(this->fresh_ingredient_id_ranges[j]))
{
++count;
break;
}
}
}
return count;
}
int64_t produce_database::get_fresh_ids()
{
int64_t sum = 0;
for (int i = 0; i < (int)this->fresh_ingredient_id_ranges.size(); i++)
{
sum += std::get<1>(this->fresh_ingredient_id_ranges[i]) - std::get<0>(this->fresh_ingredient_id_ranges[i]) + 1;
}
return sum;
}

30
05/src/produce_database.h Normal file
View file

@ -0,0 +1,30 @@
#ifndef PRODUCE_DATABASE_H
#define PRODUCE_DATABASE_H
#include <vector>
#include <string>
#include <iostream>
#include <stdint.h>
class produce_database
{
private:
std::vector<std::tuple<int64_t, int64_t>> fresh_ingredient_id_ranges;
std::vector<int64_t> available_ingredient_ids;
void parse_input(std::vector<std::string> input_ranges, std::vector<std::string> input_ids);
public:
produce_database(std::string filename);
int get_fresh_ranges_size();
std::tuple<int64_t, int64_t> get_fresh_range_from_index(int index);
int get_available_ids_size();
int64_t get_available_id_from_index(int index);
void debug_fresh_ranges();
void debug_available_ids();
void union_ranges();
int64_t get_available_fresh_ids();
int64_t get_fresh_ids();
};
#endif

30
05/src/read_input.cpp Normal file
View file

@ -0,0 +1,30 @@
#include "read_input.h"
using namespace std;
tuple<vector<string>, vector<string>> read_input_from_file(string filepath)
{
vector<string> ranges;
vector<string> ids;
ifstream input_file(filepath);
string input_buffer = " ";
bool is_after_ranges = false;
while (getline(input_file, input_buffer))
{
if (input_buffer == "")
{
is_after_ranges = true;
continue;
}
if (is_after_ranges)
{
ids.push_back(input_buffer);
continue;
}
ranges.push_back(input_buffer);
}
input_file.close();
tuple<vector<string>, vector<string>> output(ranges, ids);
return output;
}

14
05/src/read_input.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef READ_INPUT_H
#define READ_INPUT_H
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include "produce_database.h"
std::tuple<std::vector<std::string>, std::vector<std::string>> read_input_from_file(std::string filepath);
#endif

59
06/README.md Normal file
View file

@ -0,0 +1,59 @@
# --- Day 6: Trash Compactor ---
After helping the Elves in the kitchen, you were taking a break and helping them re-enact a movie scene when you over-enthusiastically jumped into the garbage chute!
A brief fall later, you find yourself in a garbage smasher. Unfortunately, the door's been magnetically sealed.
As you try to find a way out, you are approached by a family of cephalopods! They're pretty sure they can get the door open, but it will take some time. While you wait, they're curious if you can help the youngest cephalopod with her math homework.
Cephalopod math doesn't look that different from normal math. The math worksheet (your puzzle input) consists of a list of problems; each problem has a group of numbers that need to be either added (+) or multiplied (\*) together.
However, the problems are arranged a little strangely; they seem to be presented next to each other in a very long horizontal list. For example:
```txt
123 328 51 64
45 64 387 23
6 98 215 314
* + * +
```
Each problem's numbers are arranged vertically; at the bottom of the problem is the symbol for the operation that needs to be performed. Problems are separated by a full column of only spaces. The left/right alignment of numbers within each problem can be ignored.
So, this worksheet contains four problems:
- 123 \* 45 \* 6 = 33210
- 328 + 64 + 98 = 490
- 51 \* 387 \* 215 = 4243455
- 64 + 23 + 314 = 401
To check their work, cephalopod students are given the grand total of adding together all of the answers to the individual problems. In this worksheet, the grand total is 33210 + 490 + 4243455 + 401 = 4277556.
Of course, the actual worksheet is much wider. You'll need to make sure to unroll it completely so that you can read the problems clearly.
Solve the problems on the math worksheet. What is the grand total found by adding together all of the answers to the individual problems?
## --- Part Two ---
The big cephalopods come back to check on how things are going. When they see that your grand total doesn't match the one expected by the worksheet, they realize they forgot to explain how to read cephalopod math.
Cephalopod math is written right-to-left in columns. Each number is given in its own column, with the most significant digit at the top and the least significant digit at the bottom. (Problems are still separated with a column consisting only of spaces, and the symbol at the bottom of the problem is still the operator to use.)
Here's the example worksheet again:
```txt
123 328 51 64
45 64 387 23
6 98 215 314
* + * +
```
Reading the problems right-to-left one column at a time, the problems are now quite different:
- The rightmost problem is 4 + 431 + 623 = 1058
- The second problem from the right is 175 \* 581 \* 32 = 3253600
- The third problem from the right is 8 + 248 + 369 = 625
- Finally, the leftmost problem is 356 \* 24 \* 1 = 8544
Now, the grand total is 1058 + 3253600 + 625 + 8544 = 3263827.
Solve the problems on the math worksheet again. What is the grand total found by adding together all of the answers to the individual problems?

View file

@ -0,0 +1,4 @@
123 328 51 64
45 64 387 23
6 98 215 314
* + * +

6
06/input/worksheet.txt Normal file
View file

@ -0,0 +1,6 @@
6 25 26 18 71 23 9 444 224 56 69 132 3 179 3 53 97 75 325 1 61 18 9 57 53 11 3785 91 6 815 24 3 1238 1 241 77 56 754 43 48 6539 15 22 4 56 5 57 219 251 66 8198 3 5 74 62 4787 568 551 275 3 931 8 5139 531 992 6499 5 79 9889 29 2 8 44 14 897 58 8973 135 445 48 537 168 68 5 5 55 32 966 58 23 27 68 46 8836 14 49 2858 7 8 478 77 67 543 9 958 845 142 64 97 4 591 85 79 73 85 545 999 9 5 84 29 66 245 762 128 9 678 6 474 9338 84 83 564 964 195 63 66 38 6749 666 526 6561 26 76 6 27 254 31 4 44 9 78 5536 56 754 5 5122 94 4 961 3 53 618 991 89 57 468 682 72 47 916 35 5 7237 3 9 26 8 741 849 63 513 58 129 113 69 451 92 372 71 85 398 96 84 25 429 76 12 74 6 89 2 27 5 5125 1 6522 868 137 3496 8 537 92 314 34 71 492 25 989 1977 912 26 7 2938 23 21 784 572 842 99 558 6 316 63 57 1 47 6 15 1796 2 7 53 622 88 16 5 4 7 89 25 6 952 9 17 76 4 51 39 3 3 9 6353 435 86 8526 26 313 14 35 59 77 8 192 7353 76 7 728 5 114 99 3654 829 1 11 38 9648 52 9761 51 8 3 6 29 73 4 75 233 2 52 52 362 7 1269 375 18 795 13 66 33 8 465 35 347 43 75 343 6491 48 8 45 7 9567 471 559 165 86 1998 95 8 817 54 89 72 53 757 51 94 1424 6 1544 27 66 79 28 763 3 95 7 288 2 171 81 119 923 57 96 58 913 8869 42 35 8 49 2 78 2 6 261 87 34 414 553 9 53 13 41 7371 129 38 9 684 7356 357 249 21 77 19 454 698 13 93 976 83 758 28 5 79 17 25 48 5841 98 22 36 6 682 7932 289 67 72 858 692 9 52 26 13 7 527 74 39 56 43 811 55 4 778 7965 37 6957 74 526 96 4 56 284 53 7137 1 97 3412 3 385 87 39 8 63 1 6 86 13 62 5 34 71 69 3 27 948 9935 26 33 967 2 8 87 89 22 9 3 63 8 12 3 62 28 43 2 11 775 773 3 85 12 124 48 51 2321 213 9 83 4 38 4 32 75 84 38 5 225 63 9 66 1974 88 362 1 21 97 43 57 46 81 9 3813 127 78 66 3 181 451 163 315 3 44 18 617 12 822 8439 74 4 833 565 4 83 852 885 365 849 41 41 1884 27 561 24 2 92 75 376 3156 5151 86 322 2 1 19 65 618 3782 548 825 28 45 6935 47 9 46 1 1624 1138 869 57 165 3212 271 929 964 37 917 19 4 351 53 55 47 952 966 95 6 751 8986 116 5 948 29 71 8 85 14 87 58 8495 5431 852 35 91 94 3 487 548 87 76 5 145 26 48 18 1789 2 9 76 538 597 34 4 3 96 9 956 263 3 43 9 96 8438 5 4 63 41 3 699 39 578 19 259 454 89 969 857 281 1 6 164 36 57 57 1 345 399 2 33 188 976 6776 25 46 79 17 85 9 276 42 922 19 58 3955 7 5625 46 5392 5639 421 833 925 53 41 4 78 51 817 4627 9 49 559 925 85 11 85 6 5776 51 796 49 423 86 698 6 28 7835 49 7932 56 14 4219 386 8 987 348 468 14 114 42 1628 99 134 95 8 159 43 3 42 2316 249 63 358 97 29 966 826 651 6746 284 164 155 71 9 22 26 73 6 68 76 13 1 9 57 49 6 83 57 724 225 79 853 357 61 4988 74 58 8 4 73 627 171 846 79 6 188 67 6 76 2 7574 1 42 69 2648 64 28 92 3 31 6 25 8 26 6 37 458 2797 31 5 3234 87 475 2924 75 87 997 8954 396 532 76 4 7 129 36 675 12 7 713 62 7 17 823 71 27 7 933 25 9 6 6633 3567 35 31 63 133 456 421 51 99 35 235 16 7 766 425 147 3 761 248 296 292 6 811 4 99 94 75 7 272 355 63 239 666 1 326 38 69 63 8 668 45 24 936 773 4 23 5323 91 617 716 89 69 63 685 5 884 37 9 878 96 634 9 29 564 4 228 82 7 2522 556 12 19 44 822 67 71 4 286 87 92 19 2 61 63 79 9255 2 2331 63 35 324 5 78 187 18 21 96 53 156 6 64 8 24 7 114 326 146 73 56 97 42 978 9 85 71 24 33 29 329 748 63 629 75 4925 833 224 478 23 14 53 55 5 84 6246 6 42 893 85 6611 5 764 56 118 2388 24 63 6 329 672 62 27 949 143 62 2 88 8 5119 42 659 67 916 16 71 37 95
61 34 67 19 359 18 53 794 654 86 924 979 483 314 3 97 92 46 169 6 87 596 7 25 35 39 36 289 17 416 26 41 3411 71 979 37 49 792 84 34 4456 87 24 1 37 5 51 25 263 3 1197 33 7 93 68 7432 894 671 363 59 887 5 5556 592 947 166 86 946 5263 828 55 652 29 95 516 33 977 797 862 86 998 418 49 6 549 69 4849 639 3 54 75 57 32 2469 11 56 1587 78 61 868 64 95 443 98 273 782 163 64 15 12 436 855 78 68 12 959 216 98 4 55 32 3222 512 695 57 8 31 33 262 8878 33 95 589 756 564 429 762 59 7299 772 462 732 54 26 4 58 821 26 61 46 83 57 615 16 44 65 8315 37 99 118 4 52 883 388 88 541 743 933 75 28 144 77 21 7832 1 563 359 85 375 521 54 429 91 57 945 66 273 84 448 74 93 485 91 65 13 619 255 19 76 45 69 76 14 34 823 65 2776 933 96 5123 8 192 97 196 18 22 989 94 927 3333 531 94 24 6947 19 739 3352 819 852 87 178 477 325 56 17 1 14 2 957 8691 79 88 21 826 21 14 45 48 59 39 892 68 463 91 39 24 39 65 21 15 68 929 533 649 91 5834 45 1862 48 12 41 42 393 928 4253 95 5 834 29 427 42 8951 858 54 552 29 2749 94 198 92 7 37 125 69 55 129 97 799 2 854 94 85 74 7578 271 35 584 99 13 36 618 325 12 823 26 314 695 7666 89 16 55 42 3858 5436 486 81 65 4471 87 144 321 557 26 28 42 229 844 922 8761 58 6794 81 337 16 4597 775 7 8497 68 835 68 123 359 437 9878 98 96 38 978 8544 79 38 67 58 451 888 93 72 822 96 72 5774 324 54 87 7 54 347 965 6941 34 923 3777 266 856 41 515 7 496 582 95 18 858 96 6549 45 783 63 56 438 41 2519 76 25 57 8 839 2681 59 21 16 288 635 255 75 37 2263 64 883 29 81 396 98 812 5 2 23 3737 35 143 39 183 89 39 324 153 73 2477 89 62 993 114 946 82 85 64 39 7 68 27 447 28 88 38 62 87 1 3786 614 5524 42 13 569 39 82 96 42 95 462 3 223 19 65 76 1155 47 19 4 324 726 166 93 373 12 145 5 69 8416 973 49 89 38 63 6 17 33 57 72 99 41 25 6 12 8679 81 772 565 39 18 51 66 79 56 12 8614 638 87 36 17 882 771 354 47 63 34 79 2581 62 477 9571 16 84 851 59 29 35 118 176 46 961 73 45 7467 89 478 21 518 88 41 122 1745 2934 21 371 68 55 26 64 268 3519 659 425 5 57 778 22 9 81 9 7951 1364 822 95 539 7885 468 153 391 33 899 61 89 385 83 36 56 864 157 836 57 125 512 568 625 138 393 767 2 85 55 876 11 3236 8368 459 82 833 86 45 444 883 22 2 25 256 65 77 949 2799 12 3 58 9517 236 57 9 1 83 8 6731 4193 36 67 4 87 1685 77 58 8226 46 52 293 47 442 68 682 976 23 671 543 134 4 93 523 78 32 78 1 748 918 33 47 498 852 8552 34 75 99 18 64 44 941 45 842 91 32 1676 3 865 75 1747 3693 936 724 681 64 66 28 574 83 676 9246 8 95 4386 9153 56 227 86 9 1245 48 862 348 629 454 378 12 43 7377 98 723 92 35 5224 486 88 649 417 752 2971 675 71 3465 35 36 46 84 478 7671 12 27 23 841 42 145 24 48 593 3245 266 3656 928 939 676 31 425 41 283 81 77 615 33 21 85 98 86 22 83 72 89 172 2864 87 585 2293 167 4365 66 63 5 7 823 996 239 269 88 1 647 424 9 32 8 1727 77 91 35 5829 118 63 69 67 5486 365 34 5 31 98 495 183 3464 88 8 7983 21 712 6764 15 96 434 61 313 329 51 38 53 976 715 183 44 8 2745 397 67 48 535 77 73 632 296 22 97 7447 8252 7818 47 162 61 438 612 696 84 757 32 596 68 8 358 387 1277 9 171 795 273 393 218 21 135 262 22 185 9 923 6764 85 432 3844 3 973 9 26 77 886 995 661 63 588 926 6 48 597 572 665 779 84 4 34 134 1 81 77 46 528 95 171 11 27 752 57 457 3479 2 9241 241 28 48 27 68 4913 83 26 626 851 13 72 9 477 193 48 4957 53 2385 72 92 914 7 1955 419 53 5 96 28 627 72 23 46 553 2 398 4168 668 88 89 42 681 514 55 96 65 71 12 27 6144 78 893 987 72 6183 984 431 97 26 88 32 44 41 262 6464 9 82 8613 18 7171 93 761 511 662 1279 95 71 43 65 243 57 18 613 611 47 7 8536 14 2483 51 294 364 558 1712 52 855 171
32 79 35 6 654 52 12 7847 214 69 883 793 5716 821 5 3 99 7393 139 48 83 735 32 71 6 4 87 615 29 19 67 21 4147 98 455 79 865 954 62 26 8395 81 16 94 92 77 64 46 65 2 72 74 38 93 19 5866 2 92 673 675 339 14 4993 46 799 1 37 7413 9754 5163 64 5774 3 56 774 87 857 395 597 66 675 3943 86 68 537 22 1385 218 8 2 2 55 595 154 11 31 476 6795 35 489 84 13 7226 54 934 227 277 67 7 12 338 2774 82 48 41 1 798 78 3 97 22 3845 913 751 49 55 81 52 598 87 521 974 23 89 519 8819 632 69 664 187 225 362 51 76 5 62 811 77 37 87 58 66 79 25 75 563 2868 52 91 792 3 16 3 983 55 3198 552 169 65 54 49 33 81 26 36 899 446 27 222 177 547 915 33 37 221 47 66 24 917 14 94 394 482 69 13 279 253 98 4518 38 48 41 95 958 318 52 8771 227 46 117 96 54 88 579 94 42 127 28 637 5943 47 817 61 624 287 683 4274 3 31 657 772 673 958 16 5 52 75 42 768 776 94 44 326 141 16 768 94 25 187 35 975 41 834 64 728 81 35 79 414 48 225 921 98 44 475 3974 1 7378 47 567 97 7 6219 877 621 973 56 544 88 427 7 119 121 31 871 67 3278 79 335 88 95 149 659 65 578 152 28 34 428 2812 83 92 46 689 394 15 153 91 42 27 574 921 528 99 68 321 598 7466 36 46 55 38 753 3788 3 2 56 2162 99 8823 73 848 8 87 31 28 189 286 386 47 2848 75 937 65 4767 697 68 1252 76 973 674 75 392 962 3297 3 37 96 29 5673 99 355 67 5 321 527 83 94 33 7 358 4469 491 489 27 3 74 538 8945 5422 45 42 7897 7 18 41 2453 9 65 564 747 15 522 86 9879 667 376 64 12 913 59 7289 85 61 1 52 972 27 21 71 49 162 451 936 57 86 3836 714 392 644 18 985 25 968 5 266 57 1532 45 594 61 5798 32 283 366 23 89 963 22 22 951 556 24 32 49 14 22 25 79 77 651 65 7232 49 56 96 6 8195 361 5222 82 87 125 85 5215 93 6 23 3698 76 999 973 32 16 1751 33 73 72 237 814 656 82 1655 89 563 3 55 257 53 78 78 74 37 27 966 69 497 53 113 94 63 57 76 7515 84 89 358 1 299 94 43 21 48 2995 958 1532 66 63 78 675 129 886 78 22 494 894 2735 11 783 6543 1 61 7936 63 97 57 676 594 48 518 16 35 436 33 951 28 424 45 27 737 3799 6746 58 2 14 989 74 34 283 891 55 812 4 78 326 89 778 17 371 6129 387 755 55 82 9381 742 96 647 99 946 48 18 986 25 93 97 731 265 646 46 983 543 9 4263 898 694 4929 75 8 325 439 17 29 71 779 9 2534 29 746 127 4 6 6 314 895 86 61 459 847 24 838 697 1933 526 89 23 49 181 89 5277 5287 25 7 79 79 1519 21 99 8267 25 73 36 424 9 8273 592 9155 721 675 29 567 79 411 914 63 99 833 81 257 421 978 2 253 214 5444 87 65 16 832 85 45 463 56 95 35 53 1297 54 574 12 7637 616 696 521 892 147 47 17 882 25 225 2336 55 27 8151 6684 28 322 39 86 569 67 494 9253 45 977 655 249 8 15 575 857 81 72 6927 69 62 68 282 844 1849 23 43 255 18 17 39 46 58 2374 82 62 41 565 49 837 19 39 474 1219 78 98 11 54 863 92 923 65 417 98 52 786 63 36 38 88 772 81 21 38 17 87 3984 53 381 4497 922 5282 96 68 1 18 188 157 964 429 99 56 214 898 33 77 98 838 88 21 748 7835 539 2 29 17 3776 916 61 72 98 39 281 192 14 67 765 7897 39 741 1358 86 33 87 76 46 383 15 2994 196 46 524 825 41 653 6487 7457 63 16 817 94 6 652 524 232 444 6579 9359 8982 99 339 24 25 597 517 85 564 57 52 1 31 31 458 1781 22 59 753 783 848 842 13 194 359 47 574 38 552 9228 7 3 1885 5 76 6 1 743 3466 853 6425 13 337 68 1 82 454 227 681 287 41 8 38 441 1 5 23 66 432 88 534 47 74 892 392 851 9797 3 7123 5 819 93 47 18 4256 416 59 359 777 9 87 52 274 891 43 9653 7564 8681 37 17 99 9 2378 143 579 1 77 581 91 313 97 278 863 81 232 8384 389 41 96 88 179 618 29 4 62 58 58 64 9939 38 631 346 46 3685 98 415 78 633 41 83 82 672 5384 7844 97 592 5823 35 815 37 938 186 11 915 83 79 155 65 68 191 93 232 392 935 76 6443 99 7273 56 412 898 521 1581 69 434 873
56 487 56 3 128 43 437 6351 7 17 145 354 6554 614 49 2 69 3666 4 24 7 875 881 96 1 8 65 264 73 63 59 45 1469 81 455 84 179 37 6422 13 51 11 66 246 66 66 26 92 87 7 73 84 85 66 41 91 5 39 37 439 97 72 6 29 96 2 88 3165 1485 2645 25 8918 2 17 552 39 17 344 16 7 76 7434 24 12 796 89 4668 395 4 5 4 447 986 954 2 38 515 8976 33 649 11 33 1511 92 17 33 365 7 7 49 17 9768 17 26 52 6 53 86 99 698 54 7594 193 22 31 32 11 59 283 8 459 781 8 6 898 2436 721 47 9 613 922 768 15 88 46 89 417 37 55 754 29 86 69 99 32 791 141 97 79 986 24 96 7 4 6 2182 554 142 15 64 17 29 82 71 63 293 171 14 1 233 577 798 8 86 932 7 86 4 415 83 169 262 194 66 86 929 914 85 1816 86 17 37 44 578 71 83 188 213 22 721 77 57 98 693 55 8 1 45 26 9273 7 565 68 291 937 897 7575 8 63 359 741 734 297 28 1 47 8 29 696 493 84 65 577 237 29 479 87 47 582 91 153 34 747 28 466 55 61 33 518 66 235 367 74 28 987 525 9 3927 8 125 14 8 7744 611 588 957 63 43 32 418 3 78 1 15 7442 1 31 86 24 76 91 837 722 43 238 882 45 3 856 3699 72 42 49 85 2557 15 75 11 81 32 928 833 221 63 4 327 49 26 43 38 6 56 66 5482 7 6 46 42 73 5196 82 9583 1 65 45 95 389 228 4 57 8889 8 531 8 7555 143 77 2864 63 59 999 55 291 6 3989 3 1 26 42 793 2 153 44 6 583 6875 38 59 58 5 744 8968 174 747 2 3 5 346 7766 1274 97 42 854 1 35 53 2687 1 76 29 536 5 13 94 2882 145 966 97 55 418 67 219 95 22 3 41 57 6 69 28 97 21 556 443 83 78 6627 632 827 958 12 449 56 629 4 442 1 499 62 84 8 7985 6 127 641 91 5 135 15 22 11 341 61 766 6 37 5 97 27 38 763 56 2647 88 65 4 39 1194 617 993 47 53 591 24 8719 79 3 6 2267 13 556 661 22 547 2214 37 69 92 769 995 474 52 7439 11 61 8 16 1 77 22 37 24 2 78 898 55 583 71 153 77 4 23 35 94 2 3 718 8 794 13 73 9 9 1212 1 4563 41 8 78 39 939 319 75 85 864 523 5557 44 97 98 8 43 1744 92 18 95 432 6 21 252 54 1 48 28 283 13 774 5 94 363 513 52 13 3 24 568 63 2 626 8 7 825 1 19 18 4 624 8 657 93 2 246 16 32 752 99 9 4 45 534 32 651 5 53 33 3 778 353 546 39 296 42 5 8366 5819 751 7542 52 7 546 836 31 7 11 616 4 6251 11 777 13 9 9 5 442 495 93 8 431 86 83 3273 551 7852 43 3 35 39 757 27 3864 1262 27 6 24 71 8693 56 89 2683 58 265 2 5433 3 6621 47 5855 579 88 2 623 31 231 83 16 7 375 56 153 333 131 5 9 326 5427 34 97 7 329 63 43 62 65 3 58 73 13 47 225 66 78 139 29 392 6 277 1 365 646 79 68 36 75 11 4216 7425 6 438 89 99 974 83 953 4317 21 944 55 435 8 7 748 41 21 2 812 52 55 16 745 44 4288 5 81 436 1 45 36 847 6 6311 79 64 6 772 16 345 76 4 788 2968 38 41 8 6 256 5 149 69 682 38 18 379 35 5 37 188 482 8 17 34 36 4 9141 5 56 5978 431 626 545 57 38 166 525 9 255 956 17 37 356 866 48 3 41 7 79 19 6554 112 328 7 92 88 9515 1296 67 42 85 46 473 94 4 39 441 93 43 7 197 48 7 5 4 54 42 68 3667 835 95 662 598 48 441 8473 9641 194 99 927 45 6 967 965 582 568 8387 4454 461 2 155 2 5 421 445 6 4359 89 5 8 64 78 634 1227 67 68 567 776 81 587 43 447 297 87 429 21 36 2739 5 1 8376 39 35 8 2 952 4642 875 1624 42 732 6 16 82 15 385 331 539 44 9 11 539 47 9 4 83 46 56 949 14 83 58 167 787 5446 84 6559 2 294 78 1 81 4649 433 81 9 354 4 78 52 985 9932 84 84 4189 9 88 3 6 67 9929 542 984 9 3 332 66 579 67 755 183 36 95 9926 72 49 21 89 211 96 28 3 47 5 65 79 1996 28 193 66 54 5459 47 88 8 789 73 87 74 632 2176 4 28 324 6726 76 96 49 177 499 8 954 52 5 524 45 28 955 96 23 32 432 59 6364 33 25 66 73 632 231 6632 53 648 657
* + * + * + * + * * + * + * * * + + * + * * + * + * + * * * * * + * + + * * + + + + + + * + + * * * + * + * + + * * * + + * + * * + * + + + + + + + * * + * * + + + + * * * + * * + + + + + * + + + * * + * + * + * * * * * * + * + * * * + * + + + * * * * * + * + * + + * + + + + + + + + + * * * + + * * + * + + * * + * * + * * + + * + * + * + * + * + + + + + + + * * * * * * + * + * * * + + + * + * + + + * + * + * + * * + + * * + + * * + + + + + + + * * + * * + * + * * + + * + + + * * * + * * + + + * + * * + * * + * * * * * + * * + + + + + * + + * + * * + + * + + * * + * + * + + * * * * * * * + + + + * * + + + * + * * + + * + + * + + + + * + + + * * * + * + * + * * * + * * + * + * + * + * + + + * * + + * + * * * * + + * * * * + * * * * + + * * * + + + + + * * + + + * + + + * * * * + + * * * + + * + * * * + + + * + * * * * + * + * + * + * * * + * * + * + * + * * * + * + + * + * * * * + * * * * * + + * * + + + + + * + * * + * * + + + * * * * + + + * + * + * + + + * * + * + + * * * * + * * * * * * * + + * * + * * + * + + + + * + * * + + * + + * + + + + * + + + * * + * * + * * + * * * + + * * + + * * + * * + * + * * * + + * + + + + + + * * + + * + * * * * * * + * * + * + * + + + + * + * + * + * + + * * + * * * * + * * + * * + + + + + + * * + * * * + + + + * * + * * + + * + + * + * + * + + * + * * * + * * + * * * * + + * * * * * * + + * + * + + + + + + + * + * + + + + * + + * + + * + * * + + + + + * * * + + + + * * + + * * + * + + * + + * * + * + * * + + * + * + + + * + * * + + * * + * * * * + + + * * * * * + + + * + + + * + * + * * + * * + * + + * * + * * + + + + + * + + * * * * * * + + * + * + + + * * + * * + + * + + + * * + + * * * * + + * + + + + + + * + * * * + + * + * + * * + + * * + * * + * * + * * + + + * + * + * * * + * + * + * * + + * * * * + * * * + * * * + * * * + * * + * + + * * * + + * * + * + * * * + * + + + * * * + + * * * + * + * + * + * + + + + + + * * + * * * * * + * + * * + * * * * + * * + + + + * + * + * * * + + + + * + + * + * * + * + + + * + + * + * * *

81
06/main.py Executable file
View file

@ -0,0 +1,81 @@
#!/bin/python
from logging import debug, DEBUG, basicConfig
from sys import argv
def parse_input(
input_filepath: str,
) -> tuple[list[tuple[list[int], str]], list[tuple[list[int], str]]]:
numbers: list[str] = []
operators: str = ""
with open(file=input_filepath, mode="r") as input_file:
input_data: list[str] = input_file.readlines()
for line in input_data:
if line.find("+") != -1:
operators = line
break
numbers.append(line)
human_math: list[tuple[list[int], str]] = [
([int(n.split()[o]) for n in numbers], operators.split()[o])
for o in range(len(operators.split()))
]
cephalapod_math: list[tuple[list[int], str]] = translate_input(numbers, operators)
return (human_math, cephalapod_math)
def translate_input(numbers: list[str], operators: str) -> list[tuple[list[int], str]]:
cephalapod_math: list[tuple[list[int], str]] = []
current_numbers: list[int] = []
current_operator = operators[0]
for i in range(len(operators)):
if operators[i] in ["+", "*"] and current_numbers != []:
cephalapod_math.append((current_numbers, current_operator))
current_operator = operators[i]
current_numbers = []
temp_number: str = ""
for row in numbers:
temp_number += row[i].strip()
if temp_number != "":
current_numbers.append(int(temp_number))
cephalapod_math.append((current_numbers, current_operator))
return cephalapod_math
def get_solutions(math_problems: list[tuple[list[int], str]]) -> list[int]:
debug(f"PROBLEMS: {math_problems}")
solutions: list[int] = []
for problem in math_problems:
if problem[1] == "+":
solutions.append(sum(problem[0]))
continue
product = problem[0][0]
for n in problem[0][1:]:
product *= n
solutions.append(product)
debug(f"SOLUTIONS: {solutions}")
return solutions
def main() -> None:
input_filepath = "input/worksheet.txt"
human_math, cephalapod_math = parse_input(input_filepath)
solutions = get_solutions(human_math)
print(f"Sum of all (human math) solutions: {sum(solutions)}")
solutions = get_solutions(cephalapod_math)
print(f"Sum of all (cephalapod math) solutions: {sum(solutions)}")
return
if __name__ == "__main__":
if "-d" in argv or "--debug" in argv:
basicConfig(filename="debug.log", level=DEBUG)
main()
exit(0)

200
07/README.md Normal file
View file

@ -0,0 +1,200 @@
## --- 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?
## --- 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?

142
07/input/grid.txt Normal file
View file

@ -0,0 +1,142 @@
......................................................................S......................................................................
.............................................................................................................................................
......................................................................^......................................................................
.............................................................................................................................................
.....................................................................^.^.....................................................................
.............................................................................................................................................
....................................................................^.^.^....................................................................
.............................................................................................................................................
...................................................................^.^...^...................................................................
.............................................................................................................................................
..................................................................^.^.^.^.^..................................................................
.............................................................................................................................................
.................................................................^.^.^.^...^.................................................................
.............................................................................................................................................
................................................................^.^...^.^.^.^................................................................
.............................................................................................................................................
...............................................................^...^...^...^.^...............................................................
.............................................................................................................................................
..............................................................^.^.^.^.^.^...^.^..............................................................
.............................................................................................................................................
.............................................................^.....^.^.^.^...^.^.............................................................
.............................................................................................................................................
............................................................^.^.^.^.^.^...^.^...^............................................................
.............................................................................................................................................
...........................................................^...^.^.^.^.^...^.^.^.^...........................................................
.............................................................................................................................................
..........................................................^...^.^...^.^.^.....^...^..........................................................
.............................................................................................................................................
.........................................................^.^.^...^.^.^...^.^.^.^.^.^.........................................................
.............................................................................................................................................
........................................................^...^...^.^.^.^.^...^...^...^........................................................
.............................................................................................................................................
.......................................................^.........^.^.^.^.^.....^.^.^.^.......................................................
.............................................................................................................................................
......................................................^.....^.^.^.^...^.^...^...^.....^......................................................
.............................................................................................................................................
.....................................................^.^.^.^.^...^...^.^.....^...^.^.^.^.....................................................
.............................................................................................................................................
....................................................^...^.^...^...^...^.^.^...^.......^.^....................................................
.............................................................................................................................................
...................................................^.^.....^.^.^.^...^.^...^.^.....^.^...^...................................................
.............................................................................................................................................
..................................................^.^.^.^.^...^...^...^.^.^...^.^.^.^...^.^..................................................
.............................................................................................................................................
.................................................^.^.......^.....^.^...^.^.^.....^...^.....^.................................................
.............................................................................................................................................
................................................^.^.....^...^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^................................................
.............................................................................................................................................
...............................................^.^.....^.^.^.^...^.^.^.^.^.^.^.^.^.....^.^.^.^...............................................
.............................................................................................................................................
..............................................^.....^.^.^.^...^.^...^.^.^.^.^.....^.^.^.^.^...^..............................................
.............................................................................................................................................
.............................................^.^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^.............................................
.............................................................................................................................................
............................................^.^.......^...^.^.^.^.....^.^...^...^...........^.^.^............................................
.............................................................................................................................................
...........................................^.^.^.^.^.^.^...^...^.^.^...^.^.......^...^.^.^.^.^.^.^...........................................
.............................................................................................................................................
..........................................^.^...^.^.^.^.^.^.....^.^.....^.^.^.^.^.^.^.^...^.^...^.^..........................................
.............................................................................................................................................
.........................................^.^.^.^...^...^.......^.^.^.^.^.^.^.^.^...^...^.^.....^.^.^.........................................
.............................................................................................................................................
........................................^.^...^.^.........^.^.....^...^.^...^...^.^...^...^.^.^...^.^........................................
.............................................................................................................................................
.......................................^.^.^.....^.^.^...^.......^.^.^.^.^...^.^.....^.^.^.^.^.^...^.^.......................................
.............................................................................................................................................
......................................^.^.^.^.^...^.......^.^.^...^.^...^.^.^.^.^...^...^.^.^.^...^...^......................................
.............................................................................................................................................
.....................................^.^.^.^.^...^.^.^...^.....^.........^.....^.^.^...^.^.....^...^.^.^.....................................
.............................................................................................................................................
....................................^.^...^.^.^.^.^.^.^.^...^.........^.....^...^.^.....^.^.^.^...^...^.^....................................
.............................................................................................................................................
...................................^...^.^.^.^.^.^.^.^...^.....^.^...^.^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.^...................................
.............................................................................................................................................
..................................^.^.^...^.^.^...^...^.^.^.^.^.^...^.^...^.^.^.^.^.^.^.^.^...^.^.........^..................................
.............................................................................................................................................
.................................^.^.^.^.^.^.^.^...^.^.^.....^.^...^.^.^.^...^.^.^...^.^.^.^.^.....^.^.^.^.^.................................
.............................................................................................................................................
................................^...^.^.......^.....^...^.^...^...^.^.^...^.^.^.........^.^.^.^...^.^.^.^.^.^................................
.............................................................................................................................................
...............................^.^.^.^.^.^.^.....^.^.^.........^...^.^.^.^.^...^.^.^.^.^.....^...^.^.^.^.^.^.^...............................
.............................................................................................................................................
..............................^.^.^...^.^...^.......^.^.^.^...^.....^...^.....^...^...^.^.^...^.^.^...^...^...^..............................
.............................................................................................................................................
.............................^.^.^.........^...^.^.^.^.^.^.......^.^.^.^...^.....^.^.^.^.^.^.......^.^.^.^...^.^.............................
.............................................................................................................................................
............................^...^.^...^.^.^.^...^.^.^...^.^.^.^.....^.^.^.^.^...^.....^.^.^.....^.^.^...^.^.^.^.^............................
.............................................................................................................................................
...........................^.^.^.^...^.^.^.^.^.^.^.^.^.^.....^.^...^.^.^...^.^.^...^.^...^.^.^.^.^.^...^.^...^.^.^...........................
.............................................................................................................................................
..........................^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^...^.^.^.......^.^...^.^.^.^.^.^.........^...^.^...^.^..........................
.............................................................................................................................................
.........................^.^.^...^.....^.....^.^.^.^.......^...^.^.^.^.^.....^...^.^.^.^.^...........^...^.^...^.^.^.........................
.............................................................................................................................................
........................^.^.^.^.....^...^.^.^...^.^.^...^.^.^.^...........^...^.^.^.^.....^...^.^.^.^.^.^.^...^.^.^.^........................
.............................................................................................................................................
.......................^.^.^.^...^.^.^.^.^.^.....^.....^.^.^.^.^...^...^.^.^.^...^.^.^...^.^.^.^.^.....^.....^.^.^.^.^.......................
.............................................................................................................................................
......................^.^...^...^.^...^...^.^.^.^.^.......^.^.......^.^.^...^.......^.^...^.^...^.....^.^...^.^.....^.^......................
.............................................................................................................................................
.....................^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.......^.^.^...^.^.^.....^.^.^...^.........^.^...^.^.^...^.^.^...^.....................
.............................................................................................................................................
....................^...^.....^.^.....^.....^.......^.^.^.....^.^.^.^.^...^...^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^.^.^....................
.............................................................................................................................................
...................^.^.^...........^...^.^.^.^.^.^.....^.......^.^.^.^.....^.^.....^...^.^...^...^.....^.^.^.^.^.......^.^...................
.............................................................................................................................................
..................^.....^...^.^.^.....^...^.....^.^.^.^...........^.^.^.^.^.^.^...^.^...^...^.^.^.^.^.^.^.^.^.^.^...^...^.^..................
.............................................................................................................................................
.................^.^.^.^.^.^...^.^...^.^...^.^.^.^.^...^.^.^.^.^...^.^.....^...^.^.^.^...^.^.^.^...^.^.^.^.^...^.....^.....^.................
.............................................................................................................................................
................^.^.^.......^.^...^.^.^.....^...^.^.......^...^.^...^...^...^...^.^.^.^.^.^...^.^...^.^.^...^.^...^.^.^.^.^.^................
.............................................................................................................................................
...............^...^.^.^.^...^.^...^.^.^.^.......^.................^.^...^.^.^.^...^.^.^.^...^...^.^.^...^...^.^.^.^.^.....^.^...............
.............................................................................................................................................
..............^.^.^.^...^...^.^.^.^.^.^.^...^.^.......^.^.^.^.^.^.......^.....^.^.^.^.^.^...^.^.^.^.........^.....^.^.....^...^..............
.............................................................................................................................................
.............^.....^...^...^...^.......^.^...^.^...........^.^.^.....^...^.^...^.^...^...^.....^.^.^...^...^.....^...^.^.^...^.^.............
.............................................................................................................................................
............^.....^.......^.^.^.^.^.^.^...^...^.......^.^...^.^.^...^.^.^.^.^.^...^...^.^.....^...^.^...^.^.^.^.^.......^.^.^...^............
.............................................................................................................................................
...........^.^...^.^.^...^.^.^.....^.^.^.^.......^.^.^.^...^.^...^.^.^...^.^...^...^...^.^.^.^.......^.^.^.^.^.^.^.^.^.^...^.^.^.^...........
.............................................................................................................................................
..........^.^.......^.^.^.^.^.^.^...^.^.^...^.^.^.^.....^.^.^...^...^...^.^.^.^...^.^.^.^.^.^...^.^.^...^.^...^.^.^...^...^.^.^...^..........
.............................................................................................................................................
.........^.^.^.^.^.^...^.....^.....^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^.^.....^.^.^...^.^.....^.^.^.^.....^.^...^.^.^.^...^...^.^.^.........
.............................................................................................................................................
........^...^.^.^...^.^.^.^...^.^.^.^...........^.^.^...^.^.^.....^...^.....^.^...^.^.^.^.^...^.^.^.^.^...^.^...^...^.^.^.^.^.^...^.^........
.............................................................................................................................................
.......^.....^.^.^.^...^.^.^...^.^.^.^.^.....^.....^.....^.^.^.....^.^.....^...^.^...^.^.^.^.^.^.^.^...^.^.....^.^.^.^...^.^.^...^.^.^.......
.............................................................................................................................................
......^.^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^...^.^...^.^...^.....^.^...^.^.^.^.......^.^.^.^.....^...^.^...^.^...^.^.^.^.^.^.^.^.^...^.^......
.............................................................................................................................................
.....^.^.^.^...^.^.^...^.^.^.^.....^.^.^.^.^...^.....^.....^.^.^.^...^...^.^.^.^.^.......^...^.^.^.......^.^...^.^.^.....^.^.^...^.^.^.^.....
.............................................................................................................................................
....^.^.^.^...^.^.^.^.....^.^...^...^...^.^.^...^.^.^.^.^.^...^.......^...^.^.^.^.^...^...^.^.......^.^.^.^.^.^.^.^.^...^.^.......^.^...^....
.............................................................................................................................................
...^...^...^.^...^...........^.^.^.^...^...^.^.^...^.....^.....^.^.^.^...^.^.^.........^.^.^.^.^.....^...^.^...^.....^.^...^...^.....^.^.^...
.............................................................................................................................................
..^.....^.^...^.......^...^.^...^...^.^...^...^...^...^.^.^.^.^.....^.^.^.^...^.^...^.^.^.^.......^.^.^...........^.....^...^.^...........^..
.............................................................................................................................................
.^.....^.^.^.^.^...^...^.^.^.^.......^.^.....^...^.^.^...^.....^.^.^.^.^.......^.^.....^...^.^.^.^.^.........^.....^.^.^...^.^.^.......^.^.^.
.............................................................................................................................................

16
07/input/test_grid.txt Normal file
View file

@ -0,0 +1,16 @@
.......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............

60
07/main.py Executable file
View file

@ -0,0 +1,60 @@
#!/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_and_timelines(grid: list[str]) -> tuple[int, int]:
beam_dict: dict = {grid[0].find("S"): 1}
split_count: int = 0
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 beam_dict.keys() and beam_dict[x] != 0) else ("^" if x in splitters else "."), range(len(grid)))))}"
)
continue
intersections = set(
[x for x in beam_dict.keys() if beam_dict[x] != 0]
).intersection(splitters)
split_count += len(intersections)
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 beam_dict.keys() and beam_dict[x]) else ("^" if x in splitters else "."), range(len(grid)))))}"
)
return (split_count, sum(beam_dict.values()))
def main() -> None:
input_filepath = "input/grid.txt"
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
if __name__ == "__main__":
if "-d" in argv or "--debug" in argv:
basicConfig(filename="debug.log", level=DEBUG)
main()
exit(0)