AoC - Day 15

:date: 2023-12-15 12:00

Part One

Seems easy enough. Interestingly Awk is quite bad at what Python calls chr and ord. I've been toying with the idea of stepping up my game a bit anyway, so I figured it was time to break out the best language for that exact functionality - and all the other functionality mentioned in the problem: C.

I cut and pasted my technique for reading dynamically allocated data in C from my C notes. And then I just had to add this logic that addressed the specified problem.

int n=1,cv=0;
for (;n<len;n++){ cv+= str[n-1]; cv*= 17; cv%= 256; }

Then I put it together with this:

$ tr , '\n'<$I|while read N;do ./15hash<<<$N;done|awk '{X+=$1}END{print X}'

Done in about 16.5 seconds.

Part Two

The first problem with Part Two was that it was so baroque. It took me quite a while to even understand what they wanted me to achieve. Once I figured it out, I realized it would want a list of a list of tuples, or something just as complex. So I went back to Python thinking it shouldn't be too hard to just add the new logic requirements. But like many of these problems it was much more of a PITA than it sounded. But finally, I got running the test data and it looked like everything was good. Unfortunately, when I ran it on the real data, the submission failed. Hmm. I almost gave up on it not even knowing where to start looking. I didn't want to compute the solution by hand. But finally while doing some random spot checks, I caught it not deleting ones that were present and marked for deletion. Hmm. Once I could see a problem (the problem it turned out) I could troubleshoot it. I finally hunted it down to an assumption I made parsing the input because I though the codes were all two letter long like they were in the test data. But in the real data, that just cut off longer ones. After figuring that out, I got the right answer in about 16s.