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
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.
No comments:
Post a Comment