Created
December 20, 2022 07:59
-
-
Save ytaki0801/d091b52e02a1c4bac7b1e4a49dce63b2 to your computer and use it in GitHub Desktop.
(2,3) Turing Machine as an UTM 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 = {0: ' ', 1: ' ', 2: '■'} | |
while True: | |
t = delta[(state,tape[head])] | |
state = t[0] | |
tape[head] = t[1] | |
head += t[2] | |
if head >= len(tape): | |
tape.append(0) | |
elif head < 0: | |
tape.insert(0, 0) | |
head += 1 | |
for s in tape: print(ds[s], end='') | |
print() | |
sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment