April 03, 2026

Solution for Advent of Code 2018 - Day 21: Chronal Conversion

Link to the puzzle text

Part 1

In this puzzle, we have program for the same virtual machine as in day 16 and 19. This program consists of multiple opcodes with 3 operands each. The virtual machine has again 6 registers and no new opcodes as compared to previous days. The input for this program is provided in register 0 and we should execute the program and find the input number for which the program exits with the lowest amount of operations executed.

We could reuse the virtual machine from the previous days to execute the program. When analysing the source code briefly, the input in register 0 is only used once. After several computations, the value in register 3 is compared to the input. If they are the same, the program exits or continues otherwise. We could therefore use a dummy value in register 0, execute the program until we reach this line and note the value we compare against for the answer. 

Part 2

In part 2, we should take the same program and find the input number for which the program still exits, but has the highest amount of operations executed.

We tried a simple approach first. Execute the program until the line where the value of register 3 is compared against the input and save the value of register 3 in a list. We can then continue executing the program until the first repeated value of register 3. 

It became clear that this approach took too long, so we reverse engineered the opcodes into a Python program. The program just performs some simple operations in a loop. We repeat these calculations until the first repeated value as the answer for part 2.

These reversed engineered version is specific to our input, so it is sadly not generalizable. 

Link to my solutions

No comments:

Post a Comment