Colleagues told me “the Advent of Code is a marathon”. By now I’m certainly feeling that.
I’ll share a bit of my experience in this blog post.
This is my first year participating in the Advent of Code (AoC), and I must say it’s a lot of fun. My personal goal is to ‘save Christmas’ using Go, which is a relatively new language for me.
Calculating chemical reactions, traversing graphs, solving a maze with breadth-first search… I’ve already (re-)learned a lot, and I feel participating in the advent of code using a new language is maybe the best programming boot camp there is. The creator, Eric Wastl, seems to have given all puzzles a great deal of attention, and there’s often some backstory related to the history of computer science.
The complexity of the puzzles can get you into the woods really quickly. One of the things that really helped me is testing. Writing proper tests helps tremendously in debugging, especially if you find yourself modifying the same piece of code several times over. Another thing that seems to be a bit of a recurring theme is visualization. This makes it easy to figure out whether the 90 degrees you’ve set is actually ‘down’ instead of ‘up’ :).
Traversing the scaffold
Today we dusted off the Intcode program again. The Intcode program takes a set of integers as instructions and executes different functions based on those instructions.
To be fair, it didn’t really collect much dust. This home-built virtual machine has been used in painting our spaceship, playing a game of breakout, and finding an oxygen machine in a maze… Now, we’ve got to navigate a scaffold with a vacuum robot.
I feel participating in the advent of code using a new language is maybe the best programming boot camp there is.
The first part of the puzzle is figuring out where the intersections are. My algorithm simply figures out whether there’s a ‘#’ surrounding the examined tile.
The second part is more difficult: now we need to actually traverse all tiles in the path and see how much dust the vacuum will collect. Because I’m a bit short on time today, I opted to get the pen and paper out and wrote down the steps the robot should take. This involved figuring out three basic patterns, since the robot could only take a limited set of movement commands. Next, I got the ASCII table out to get the commands to the robot in the correct format. Add a small bit of logic, and boom, there goes part two!
Another one down..
It’s not the solution I’m most proud of. Ideally I’d have invested in a solution that could handle other scaffolds as well, but oh well… Running a multiple-day marathon means you might have to go for the less pretty option sometimes.
If you’re doing all of the puzzles later, though, just believe me when I say that it’s worth it to invest some extra time in the Intcode program 😉.