Hello everyone and especially the Naggernation, it’s time for your Advent of Code 2021 Day 3 cruising log. Waka Flocka!
Today felt harder than I think it really was. I will definitely blame this on getting less sleep than yesterday. My brain was quite foggy when reading the problem. The whole epsilon and gamma rate stuff is simple once your brain parsed it but jeez did my brain take its time.
Basically, in today’s problem, it was all about binary numbers. Year one school kind of thing. Yet I took a second to google if there was a java.util bound function to convert from numbers to binary and vice-versa. I wasted most of my time in part one getting that conversion going. After five minutes of googling, I felt ashamed about the thought of using a library and decided to write this myself. After all, all it takes is using the right powers of two for a given index. I know, a 6 am brain is not meant to do that but hey, I’m awake and the game is on so I’m gonna play.
Once that sand grain was out of the way I went back to read the problem description. All I had left to do was some comparison work to figure the most and least common bits per index in a data set. Pretty straightforward, my unit test using the sample data went green and I run the console app. Surprisingly, I got an exception and it broke.
I spent a good ten minutes trying to figure how I could get an exception about being out of bound when all lines should have the same size. The answer is simple: they didn’t. After adding some random prints, I noticed the issue from the next run. Like a dum dum, my code was pointing at the day 2 input file. I fixed that, ran again and this time I got to claim the first star of the day.
Now the second part started the real fun. Even though it took me a few reads to parse what I had to do there it felt obvious. The most/least common bit thing from the first part was gonna play a crucial role but with a twist that I won’t spoil here. Still took me half an hour to wrap it up as my test yielded exceptions and other shenanigans. Shenanigans that I could have avoided if I copy/pasted my code like the throwaway software it is. Eventually, I was done and could move on with my day. Write this blog post, go and work out my arms and chest then finally, a bacon and eggs breakfast. This will be a good day.
Thank you for reading my Advent of Code 2021 Day 3 log, I will see you tomorrow. As usual, I will push the code to my repo for this year on Github. Feel free to check out my Day 2 log right here.
PhoPhoto by sergio souza from Pexels