Advent of Code - Day 9 to 12

I’ve got a bunch of code to share so let’s get started. As before, be sure to check my repo for the full code of my solutions.

Day 9

Day 9 was a doozy. Basically the idea was to work with a compressed string, think a zip file, and decompress it. Part one used this rule: Given the existence of (XxY) in a string, it means that you repeat the next X characters Y times. Your solution needs to decompress the string and output the length.

Nothing too crazy here, just a bunch of string manipulation. Part 2 did something crazy. Previously, if you found a marker within text that was being repeated, you ignored it. Now you need to decompress that too. What happens now is that the string gets so big, you run out of memory! So along with continuing to decompress, I had to switch my code to not actually create the result string, but just keep track of the length.

Day 10

Day 10 was another fun one (two in a row, I should have known what was coming next). Basically your input is a set of instructions to bots that take values from an input bucket and then, eventually, copy them to an output bucket. Bots can hold two values and then have a rule saying, “I give my lower value to bot X and my higher value to bot Y”, or instead they can copy a high/low value to the final output bucket. Your goal is to figure out what bot “held” values 61 and 17.

Part 2 simply asked you to output the product of some of the values in the output array, and since I had output them already, I didn’t need to write any code at all.

Day 11

Well, it happened. Day 11 was the day that finally brought me to a complete stop. Intellectually I understood the problem, but honestly I couldn’t see any way I was ever going to solve it. Last year when this happened I typically found a solution in another language and rewrote it in JavaScript, but I was a bit short on time so I really cheated. I found a Python solution and simply ran it. As I didn’t have Python installed yet, I figured I was at least correcting that problem too.

Day 12

Woot! A fun one again! And one that’s based on a puzzle from last year if I’m not mistaken. Day 12 basically has you implementing a little Assembly-like language. So for examlpe, your input may be:

cpy 41 a
inc a
inc a
dec a
jnz a 2
dec a

Your code either moves/sets values in registers or has you change the order of code execution. Outside of a few dumb mistakes I made, this one was simple.

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos.
If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.