advent-of-code/2024-python
Anders Englöf Ytterström 9a7a9c878b Solve 2024:12 p2 "Garden Groups"
Funny that original 2023 day 5 also was a PITA
to figure out.

Pt 1 was solved using BFS to flood-fill. After
trying some different methods for pt 2, including:

- wallcrawling,
- side couting,
- corner counting

I never produced code to get past the test cases.

- Wall crawling are hard due to overlapping
regions.
- corner couting and side counting are both hard,
but will act as equally good solutions (since side
count equals corner count).
- Concave corners are hard, convex corners are
easy.

The final code is based on the posts on the
solutions megathread. Changes:

- Keep all areas in a set, defining a region.
- find all convex and concave corners in each
region.

A new helper got introduced: Di, storing all
diagonal neighbors for grid traversing.

Convex corners:

..  R.  .R  ..
R.  ..  ..  .R

Concave corners:

RR  .R  R.  RR
.R  RR  RR  R.
2025-01-05 00:06:18 +01:00
..
output Solve 2024:12 p2 "Garden Groups" 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