9
votes
Day 9: Sensor Boost
Today's problem description: https://adventofcode.com/2019/day/9
Join the Tildes private leaderboard! You can do that on this page, by entering join code 730956-de85ce0c
.
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
I spent a few minutes fighting the Crystal compiler to convert from
Int32
toInt64
s everywhere I needed them, so I hopped back over to my Ruby version to slap together the necessary bits to get the puzzle answers, and then back to Crystal afterwards.My Ruby Intcode module hasn't had quite as much love as the Crystal version, but at least changes there didn't require me to go back and update previous days (I have every day with Intcode linking into the same library).
Day 9 Intcode VM
VM Module
Opcodes
Now that we (presumably) aren't going to be adding any major new features to the VM, I went back and refactored out a lot of the indirection in my setup. Interestingly, when compiled in release mode, the performance of the new version is almost identical to the original. However in debug mode, or with the ruby version, it is a good bit faster now.
Intcode VM - Take 2
I'm really excited to see how the intcode computer gets used in further problems. I wonder what tricky problems could come up next now that we have the intcode computer established. Maybe we'll have to repair an intcode problem or do some kind of analysis with one.
This is the farthest I've gone on any of the Advent series so far, but based on some of the authors other work I do expect exactly that.
The Synacor puzzle had a tricky "disassemble -> reverse engineer -> optimize" challenge towards the end.
I really enjoyed the Day 7 coordination/communication puzzle though, I hope we get more of that style too.
Used today to clean up the intcode VM and convert it to using the result monad instead of exceptions inside the VM. Now that the step function, that calculates state according to the previous one is stateless, it should be quite simple to go for day 7 part 2.
Intcode module
Part 1 and 2
So now the intputer is fully functional. Part 2 isn't actually any different than part 1, which on one hand felt a bit disappointing, but on the other a free star is a nice reward for all the work spent on the intputer
Part 1 & 2 - Python
This is almost exactly the same intputer as the one I used for day 7, but read_value and write_value were modified to enable parameter mode 2, and I added opcode 9, which was pretty simpleWell, that was easy, partly because AWK (or at least
nawk
) isn't strict so everything but the new mode came in free. Although I sort of cheated here and hardcoded the input handling. I'll try to clean it up later as I'm not feeling well right now.Parts 1 & 2
EDIT: Cleaned up a bit.
Well, I had a busy day yesterday and didn't get to this, but it's done now. Assuming we see the Intputer again, I fully expect to spend time refactoring it into an object. That would make it much easier to be compatible both with the new features from these challenges, and the management of several simultaneous Intputers from before. Anyway, Python solution below:
Parts 1&2