December 30, 2024

Solution for Advent of Code 2017 - Day 25: The Halting Problem

Link to the puzzle text

Part 1

In this puzzle we have the configuration for a turing machine. We should run this configuration for a certain number of steps and report the number of 1 symbols on the tape.

A turing machine consists of an infinite tape of cells, a read/write head and a state. The head reads the value on the current position. Depending on the value and the current state, the head writes a new value on the current position, moves 1 cell in a direction and changes its state.

This can be implemented straight forward, most of the other code was reading in the config:

tape = defaultdict(int)
current_location = 0
for i in range(num_steps):
tape_value = tape[current_location]
next_value, direction, next_state = config[(state, tape_value)]
state = next_state
tape[current_location] = next_value
current_location += direction 

Part 2

As usual the last day has no part 2, so we are done for 2017.

Link to my solutions

No comments:

Post a Comment