Created
December 1, 2022 21:01
-
-
Save ognis1205/6efaebcf8bd178b9bb1b4dca4eb8fba7 to your computer and use it in GitHub Desktop.
Wolfram's 2-state-3-symbol Turing Machine in Python
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
from time import sleep | |
delta = { | |
1: { | |
0: ( 1, 1, 2), | |
1: ( 2, -1, 1), | |
2: ( 1, -1, 1) | |
}, | |
2: { | |
0: ( 2, -1, 1), | |
1: ( 2, 1, 2), | |
2: ( 0, 1, 1) | |
} | |
} | |
chars = { | |
0: ' ', | |
1: '.', | |
2: '*' | |
} | |
len_tape = 80 | |
tape, head, state = [0] * len_tape, len_tape // 2 - 9, 1 | |
while 0 <= head < len_tape: | |
next = delta[state][tape[head]] | |
tape[head], head, state = next[0], head + next[1], next[2] | |
for s in tape: | |
print(chars[s], end='') | |
print() | |
sleep(0.005) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment