Advent of Code 2019

The story of my slow descent into madness

View on GitHub
25 December 2019

Day 25: Cryostasis

by Simon Berger


Links:

And here we are, what a journey it’s been. Today’s puzzle was, as expected, another intcode problem. But it wasn’t about springcode, sadly. We also didn’t find out what the network from day 23 was about. All in all, my predictions were completely off. We got a fully-fletched text adventure though so you won’t see me complaining. It’s incredible. The game isn’t necessarily fun to play yourself but it feels really good seeing your intcode emulator do something like that.

Puzzle Discussion

Of course, because today’s Christmas, I didn’t have a whole lot of time. My solution is thus rather undeserving of the puzzle. I’m ashamed to even go into how it works, it’s that bad. But anyway, the gist of it is that everything’s random. The droid always moves in a random direction and picks up items until it reaches a pressure-sensitive floor. If the droid doesn’t have the correct weight, the machine is reset to its initial state and the randomness begins anew. There is some nuisance to the item collection though. The droid keeps track of all items it has ever encountered (across resets) and which items it mustn’t collect because they lead to a game-over. Additionally, when the droid encounters an item it has already seen in a previous run it isn’t certain whether it will pick it up or not. At the start of each run the droid determines a subset of all items and it only collects items that are in this subset (with the exception of items it has never seen before).

Rust doesn’t have a built-in way to generate random numbers, so I had to write my own PRNG. I decided on a Xorshift generator which worked out pretty nicely.

I just realised that I’m using a 64-bit xorshift* variant to generate “usize” numbers. This approach would crash on 32-bit systems because the “magic number” 0x2545F4914F6CDD1D takes 62 bits to store. Oh well shrug

The code takes a bit of time to run but it works.

Like previous years today’s puzzle only has one part. There is a second part, but it’s just “have x amount of puzzles solved” and if you’ve already solved all other puzzles there isn’t anything to it other than pressing a button. I may be lazy but I’m still willing to do that manually. My fancy new macro really doesn’t like the fact that day 25 doesn’t have a second solver function though. I had to manually add it as a special case. It’s not the end of the world but I’m still kind of disappointed. I wanted to add a “does this day have a second part” check to the macro, I really did, but as far as I know Rust’s macros aren’t that dynamic.

Other stuff

First of all, happy holidays! With that out of the way, let’s have a meta-talk.

Some depressing things first:
While I’m writing this not a single person (other than me) has read any of these posts. Don’t worry, I wasn’t expecting anything else. I pretty much just wrote these posts for my own pleasure so I didn’t tell anyone about it. There is a part of me that would love to share this with others though, as you can probably tell from the way I’m writing. If you’re reading this, whoever you are, I would love to hear from you! There are numerous ways to contact me, you can find (some of) them on my terribly outdated website siku2.io.

But enough of that, let’s talk about my final product.
Now that it is able to solve all puzzles I would love to distribute the CLI as a GitHub release but I’m too tired to do it right now. I hope to have it done by the end of the year (ambitious goal, I know!).

My highlight of this year definitely has to be the intcode machine. I’ve already gone over how much of a good idea I think it is even though many people might not agree. I sympathise with the person solving the puzzles in Excel (big fan btw) who had to reverse-engineer all intcode problems to solve them. I think they might have started to appreciate the additional challenge though. I don’t have anything else to say about it, I just wanted to mention best boy u/pngipngi.

Finally I would like to sing praises to Advent of Code one more time. I found out about it in 2017 and I’ve loved it ever since. I adore solving the puzzles and gawking at other people’s approaches afterwards. Another thing is the community. Take one look at the subreddit and you see how enthusiastic the community is. Take it from someone who cringes at most uses of the word “community”.

I look forward to next year!

tags: intcode
Overview
Previous day