Created
December 10, 2022 12:31
-
-
Save ytaki0801/1fee4e176eddb0a990d4aeff9434c1a6 to your computer and use it in GitHub Desktop.
Wolfram's 2-state 3-symbol Turing Machine as an Universal TM with Turtle Graphics
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
# Wolfram's 2-state 3-symbol Turing Machine as an Universal TM | |
# with Turtle Graphics | |
from time import sleep | |
from turtle import fd, rt, lt, setup, setpos, clear | |
setup(height=500); setpos(100, 0); clear(); sleep(5) | |
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)}} | |
tape, head, state = [0] * 29, 10, 2 | |
while 0 <= head < len(tape): | |
print(''.join([str(n) for n in tape])) | |
t = delta[state][tape[head]] | |
tape[head], head, state = t[0], head + t[1], t[2] | |
fd(30) | |
a = (1 + t[0]) * 45 | |
if t[1] == 1: rt(a) | |
else: lt(a) | |
print(''.join([str(n) for n in tape])); sleep(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment