Skip to content

Instantly share code, notes, and snippets.

@ytaki0801
Last active December 10, 2022 14:44
Show Gist options
  • Save ytaki0801/ed7c48e6d70aabc1ffd76baeda2f5b4c to your computer and use it in GitHub Desktop.
Save ytaki0801/ed7c48e6d70aabc1ffd76baeda2f5b4c to your computer and use it in GitHub Desktop.
Wolfram's 2-state 3-symbol Turing Machine as an Universal TM with Turtle Graphics
# 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, setpos, pu, pd
pu(); setpos(-300, 300); pd(); 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] * 30, 10, 1
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