Advent of Code 2023 Week 1

Christof Reimers

485 words, 3 mins

Hey, it's that time of the year again.

This time, I once again am using JavaScript, I think I am in a comfortable place right now. Things I have changed is how I go about running everything. While doing stuff for university, I once again remembered how useful tests can be.

That's why I run at least one test for each part, that is the given example with its given solution. When I feel like it or think I probably should test more than that I create more tests, like today for example.

Day 1 and day 2 were easy warm up, nothing special there.

Looking back at this week, there were a few good days and a few nasty days. My code for day 3 is wildly inefficient and runs in roughly 3 seconds for each part on my notebook. Besides that I think I managed that day quite well.

Not so with day 5. While it was a fun idea, the second part just turned my brain to mush. Finding the overlapping ranges and mapping them and so on and so forth was nothing for my brain to handle. At some point I thought I was clever and with just hacking ranges into small pieces based on where other ranges end or begin would be a naive and crude approximation - guess what, that is perfectly fine and totally the right idea to make this thing efficient. Another thing that immensely helped me was not treating ranges as a startpoint and a size, but the first and the last element in said range. Besides this I built up a lot of bugs which slowed everything down quite a bit (I don't know why I didn't do thorough testing this time). There were quite the few, like in merging overlapping ranges back together (which always reduced them to less than a handful, which is very nice). In the end I spend waaaaaay to much time on this day, but the end result was worth it.

Easier were for example day 4 and day 6. Day 4 was quite fun and easily solvable with the reduce function in JavaScript, day 6 was just solving a quadratic equation. Although I still don't know why the rounding and subtracting one works.

Today was a fun day. I very much remembered efficient code to analyze mahjong hands (primarily a shanten calculator) and based on that knowledge I implemented this in a similar fashion. Once again I used a lot of (probably unnecessary) tests to test every last bit, but this helped me in the end to come up with an even easier method to get the best hand for the jokers (take a look here and compare it to the version right above).

In a nutshell, I am quite happy with this week and how I structured the code. We will see how far I get this year.