December 29, 2023

Solution for Advent of Code 2015 - Day 23: Opening the Turing Lock

Link to the puzzle text

Part 1

In this puzzle, we get the first of many "simulate pseudo assembly language" ones. Here we have a machine with 2 registers and 6 different opcodes. We are asked to get the content of one register after exectuting a provided program.

When simulating, we parse every line and check via regex which ones of the opcodes match. The function relevant for this opcode is then executed. The registers and the instruction pointer are both global variables to simplify the handling. Once we hit an instruction outside the provided program, we terminate and print the result.

Part 2

For part 2, we are asked to execute the same program, but initialize one of the variables to 1 instead. No further modification was needed.

Bonus

We also converted the provided program into a more readable form. It computes the number of steps until a given number converges to 1 when following the Collatz series. Based on the initial value of register a, we start at different points in the series.

Link to my solutions

No comments:

Post a Comment