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