February 06, 2026

Solution for Advent of Code 2018 - Day 19: Go With The Flow

Link to the puzzle text

Part 1

In this puzzle we have a program consisting of multiple opcodes. The opcodes are executed by a virtual computer with 6 registers, one of which is the instruction pointer saving the current instruction. We should execute the program and return the content of register 0.

The opcodes are the same as in day 16, so we could reuse a lot of the code. The first line of the program contained metadata about which register is the instruction pointer, so after parsing it we deleted it from the rest of the program. 

Part 2

In part 2, we have the same program but we should initialize one register with a different value instead. We should still execute the program and return the content of register 0.

After letting the previous solution run for a while it still did not finish so a different solution was needed. We converted the opcodes manually into a more readable form and analyzed its function. The program is calculating the sum of all divisors for a given input number determined by the value of register 0 at the start.

We changed the previous solution to run until it finished initialization. Then we stop the execution and calculate the divisor sum in python instead. This was checked against the previous solution and can be turned off via a flag.  

Link to my solutions

No comments:

Post a Comment