Hello, there and welcome to my Advent of Code 2020 Day 8 cruise log. It’s time for the developers to assemble as we’re getting a hint of this year’s main event. We will get a confirmation with the next couple of days but now my money is on today becoming the thread. Writing a code interpreter for what looks a lot like the assembly language. No way we don’t reuse that throughout the next few weeks. As one expects I will spend some time later to clean it up and probably move the classes to a separate package.
The level of parsing required was shockingly low as it wasn’t the focus of the day but I still had my ParseMan fix. Each part roughly took me about half an hour to complete. It feels reasonable at this level but I can’t stop myself from thinking that I should have been able to wrap today faster. Reading the first part my brain was fairly foggy so that may have played a part. While the second part was much easier for my brain to parse, the first definitely required a few additional reads.
So in part one, we needed to implement some assembly-bootleg interpreter that would stop executing before entering an infinite loop. Once the subject is understood it turns out to be much easier than one could picture. I’m glad I did pretty quick work of it. I tried to limit how much optimisation would go into it as it wastes time. Especially if the second part goes in a very different direction from what I expect. As usual, well since day 4, I am going full TDD on this sucker to move more efficiently. All tests passed on the first run, so did the input.
Then in part two, we’re introduced to the concept of program fixes. Permutations that would fix the program and stop it from entering an infinite loop. Thus allowing it to run to the end. Fairly easy to do with the right abstraction. I introduced the concept of a multiverse of programs that I generate for each possible permutation. From there I execute code from the first part to find which alternate program will not hit an infinite loop. I was confident enough here to write only one test for the whole second part this time. The test passed, and so did the input. I’m definitely looking forward to comparing what I did with others and whether there is a more efficient way to test permutations than my multiverse solution. It’s almost 6.30 am and now I need to go workout.
Thank you for reading my Advent of Code 2020 Day 8 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!
Photo by ROMAN ODINTSOV from Pexels