5
votes
Day 17: Chronospatial Computer
Today's problem description: https://adventofcode.com/2024/day/17
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>
Part 1 was straightforward conversion of requirements to code.
For part 2, based on inspection of the code (in my input, have no idea how well this generalizes), I saw that the same prefix in the octal representation in register A always corresponded to the same suffix in the output, so I built up the output by adding to the prefix of register A digit-by-digit and seeing which next digit(s) correspond to the desired output.
Part 1 (Python)
Part 2 (Python)
Pretty fun day! Very reminiscent of a previous year (I can't remember which one) which also relied on interpreting the given instructions. I think that day was about optimizing them, whereas today the only necessary information was how the A register was iterated over 3 bits of at a time (I'm assuming this was the same in everyone's input, or at least similar).
I'm still getting burned by indexing from 1... Today it was that
findNext:
returns a 1-based index, or 0 on failure.Computer Simulator
Solver
God. Part 2 was time-consuming, but I'm kind of proud that I solved it without help.
Rust (Part 1)
Part 1 was very boring; everything worked on the 2nd try -- The Sokoban puzzle was much more interesting.
Part 2
Part 2 took a long time. I transcribed the machine code back into a more high-level representation and noticed that
a
is only ever divided by eight.It would probably be possible to just derive the bit pattern for the registers if you stare at it hard enough, but I took this as an opportunity to play with Z3.
After a few skill issues with getting it to do XOR and 2**X operations (not to mention the sidequest of translating the entire fucking VM into Python because the Rust bindings aren't complete for Z3), I had an answer that produced a quine; however, it was too high. Then I was left scratching my head, because Z3 refused to find answers below it, and if I gave it a constraint not to exceed the known result, it produced even higher numbers. Finally, after fiddling with the number of bits in the
BitVec
s, it finally spit out an answer that the AoC site accepted -- though I'm not sure if I just got lucky there. :(I managed to finish this with only about five minutes left before midnight - phew! I'm posting the solution now since I had to immediately move on to tonight's actual puzzle.
It took me quite a while to finally realize I should be looking at what the program actually did, and once I saw what it was doing it didn't take too long to figure out a solution (just bruteforce three bits at a time). I ended up having to use BFS for the bruteforcing, since otherwise it seemed it kept getting stuck on false leads.
Solution (Jai)
This took some time but it was fun.
I also regrettably asked a friend for their test case to see if my program would work and it didn't. So I decided to modify mine to account for both (and now hopefully ALL) test cases that they could throw out.
Details of this journey are here.