Advent of Code: Day 23
Opening the Turing Lock

First puzzle

Here we go to execute assembly code! In this puzzle, we received a set of assembly-like instructions, and we need to find the value on one of the machine registers after the instructions are executed. This particular “machine” has two registers (a and b) and six instruction:

The offset value will be prefixed with + or - indicating the direction of the jump. The instruction execution ends when you are trying to execute an instruction outside the provided set.

The puzzle solution is the value of register b after the instructions are executed.

A convenient way to parse the instructions is to convert them into functions. Each instruction could be a function that receives the current state and returns the next one. The state of this machine is next line to be executed and the register values:

Once the instructions are defined as function, the only thing left is to execute them until the next line is out of the instruction collection:

Second puzzle

The second puzzle only changes the initial value of register a to 1. We still need to find the value of register b after the execution finished:

You can find this code along with my input and puzzle answers at here.

*****
Written by Darien Martinez Torres on 23 March 2016