AoC - Day 10

:date: 2023-12-10 12:00

Part One

I always hate problems like this. It might as well say: "Start by writing a crappy 2d game engine..." Because that is really what you need. A map and a way to move around it and do things with what is found without running into trouble with the edges, etc. This is all very easy, but not small. There are no (simple) shortcuts to checking for all the things that need to be checked. With that in hand I was able to trace around the pipe. Of course there were annoyances like the starting location not having its shape specified so you have to iterate through that.

Part One

On to part two and I was thankful I'd read the ORA OpenCV book which discussed finding borders in pixel arrays (think "bucket fill") which may or may not include "islands". Anyway, I knew the basic strategy was to count up the borders and mod two is the answer to whether it's inside or outside. Of course the problem made the borders kind of ambiguous. Probably a good time for a Python regular expression, but I just don't like using them short of a full on crisis. The number I got was wrong. I looked at the map of my results and saw a line of "ins" conspicuously on the outside of the whole mess. I just counted those up and added it to my number and that was the correct solution! Only then did I realize what had happened: the starting S symbol stayed an S and messed up the count. I could have written some code that detected what the starting pipe form was but, really, there was only one. I could have just replaced it by inspection. Instead, my ultimate technique worked and was no worse.

This challenge took me a long time today. Just too many details that have to be wrangled. There's never anything elegant about 2d grid worlds!

Though check out the spectacular final map that I plotted showing my calculated inside ("X") and outside ("O"). See if you can spot the error.

10-day.png