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.