Created
December 22, 2022 07:56
-
-
Save ytaki0801/fd8d5b2aff6191756728f281c9464484 to your computer and use it in GitHub Desktop.
Wolfram's (2, 3) Turing Machine as an Universal TM with an Infinite Tape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (2,3) Turing Machine as an UTM | |
from time import sleep | |
# (state,symbol) => (state,symbol,head) | |
delta = {(0,0): (1,1, 1), | |
(0,1): (0,2,-1), | |
(0,2): (0,1,-1), | |
(1,0): (0,2,-1), | |
(1,1): (1,2, 1), | |
(1,2): (0,0, 1)} | |
state, tape, head = 0, [0], 0 | |
ds, space = {0: ' ', 1: '.', 2: '#'}, 40 | |
while True: | |
t = delta[(state,tape[head])] | |
state, tape[head], head = t[0], t[1], t[2] + head | |
if head >= len(tape): | |
tape.append(0) | |
elif head < 0: | |
tape.insert(0, 0) | |
head += 1 | |
space -= 1 | |
for _ in range(space): print(' ', end='') | |
for s in tape: print(ds[s], end='') | |
print('\r', end='') | |
sleep(0.008) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment