advent-of-code/2024-python
Anders Englöf Ytterström e6307795a4 Solve 2024:14 p1-2 "Restroom Redoubt"
After working overtime to solve day 12, this brief
task was a much welcome change.

For pt 1, the code uses integer division and
modulus to update all positions. The tricky part
was to determine which quadrant got the middle
column and row (since dimensions was odd numbers,
and either left or right quandrants is +1 longer),
which was straightforward to verify by the test
cases.

For pt 2, the remains of the code used to visually
identify the tree is left under the `find_easter_egg`
toggle.

Basically, the code prints the grid with
all robots marked as a `#`, and free space as `.`.`

This wording of the puzzle is important:

> very rarely, _most of the robots_ should arrange
> themselves into a picture of a Christmas tree.

"most of the robots" means the tree will be quite
visible, which also means it is safe to asume a
significant cluster of "#" would appear over time.

By keeping track of the counter (seconds the robots
has traveled), it was evident that the cluster of `#`
occoured th first time at i=64 and every 103th
time forward.

In other words, `i % 103 == 64` will most likely
give a tree. The print statement is therefore
limited to those i's, and at `i == easter_egg_appearance`
the tree is visible.

So, to be extra clear: 64, 103 and pt2 answer is
unique to my puzzle input. If this code is used
with any other puzzle input, these numbers will
most likely vary.

For the fun, the code also contains the `display_easter_egg`
flag to actually print the tree. This is provided
to indicate how big the actual tree is: 33*36 chars.

Also, the `sints` utility function was added to
extract all signed ints from a string.
2025-01-05 00:06:18 +01:00
..
output Solve 2024:14 p1-2 "Restroom Redoubt" 2025-01-05 00:06:18 +01:00
aoc.py Solve 2024:9 p1-2 "Disk Fragmenter" 2025-01-05 00:06:18 +01:00
README.md Prepare for AOC 2024 2025-01-05 00:06:18 +01:00

Advent of Code 2024

Solutions for #aoc2024 in Python 3 (3.12.7).

Programming setup:

  • Lenovo Thinkpad X260
  • Arch Linux with Hyprland
  • Zed editor (Ruff, Pyright)
  • Firefox
  • Alacritty

Help scripts

Display all solved puzzles:

python aoc.py

To bootstrap a new puzzle (creates input/<day_no>.txt and output/day_<day_no>.py):

python aoc.py <day_no> new

Manually copy the puzzle input from https://adventofcode.com and paste it in input/<day_no>.txt to start coding.

wl-paste > input/<day_no>.txt

Solve separate puzzle (replace XX with the puzzle number):

python -m output.day_XX

Solve separate puzzle using stdin (replace XX with the puzzle number):

wl-paste | python -m output.day_XX
cat tmpfile | python -m output.day_XX

Execute separate puzzle on file save (replace XX with the puzzle number):

ls output/*.py | entr -c -s 'wlpaste | python -m output.day_XX'
ls output/*.py | entr -c -s 'cat tmpfile | python -m output.day_XX'
ls output/*.py | entr -c -r python -m output.day_XX

(requires entr and wl-paste, Mac users can instead use pbpaste. If you prefer X at Linux, use xclip -selection clipboard -o).

To lint files:

ls output/*.py | entr -r -c flake8 output --ignore=E741,E501,E203