Hello, there and welcome to my Advent of Code 2020 Day 5 cruise log.
Today’s challenge is about writing an algorithm that allows for scanning boarding passes and detects which one is missing because you can’t find yours. Fortunately, the plane is full even though that is no mention of that. Still, it’s a healthy assumption since you need that condition for the algorithm to work.
The first part consisted of validating the scanning by finding the highest pass ID after decoding boarding passes through binary space partitioning. I don’t believe I came across that before, however, the logic is close enough to dichotomic search for me to pick it up easily.
The part that took me the most time here was writing the tests to parse the encoded passes on part 1. Actually, within the tests, there is one that took some time for me to figure. I started by writing tests to validate that both row and seat could be appropriately decoded. Both passed after I wrote my binary space search method used to decode both seat and row. However, the test to validate that the whole thing could be decoded into my boarding pass struct failed.
From there, I assumed one of two things happened. It’s possible that I failed my string split of the encoded pass into an encoded seat and row. Another option is that my test input is wrong. I first realised my split was wrong as neither seat nor row had the right value. But then after changing the algorithm to make it work after fixing my split all the other tests broke. This is where I realised that my test input for the whole pass test was invalid too. Probably wasted a good twenty minutes of that but at last, this ended. Basically, the whole pass test failed because I pasted the example value from the website when I wrote it for the other tests. There must have been an invisible character that snuck in and ruined the test.
Once I completed the first part, I tackled the “finding my pass” second part pretty fast. I still wrote a couple of tests to ensure no unneeded error would sneak in. Within fifteen minutes I wrapped it up too. Only had to list all IDs, sort them and find the hole. A pretty neat and straightforward solution. Plus I got to expand my practice of Go which is great.
Now onto the lessons learned today. Similarly to yesterday, I decided to sacrifice once more speed to efficiency. Even though it feels costly in the early days with relatively easy problems it should pay dividends in pas day 10. Going full tortoise and the hare in here. Let’s see how that goes.
Thank you for reading my Advent of Code 2020 Day 5 cruise log, I will see you tomorrow, maybe. In the meantime, you can check out my Go Cloud series about building and deploying a Golang app to AWS. Also, I will push my code on Github at CodingNagger/advent-of-code-2020 so feel free to check it out but not before you’ve done the challenge yourself. Bye!