File: turing_client.py

package info (click to toggle)
pytango 10.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,216 kB
  • sloc: python: 28,206; cpp: 16,380; sql: 255; sh: 82; makefile: 43
file content (22 lines) | stat: -rw-r--r-- 558 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# SPDX-FileCopyrightText: All Contributors to the PyTango project
# SPDX-License-Identifier: LGPL-3.0-or-later
from turing_machine import TuringMachine

transition_function = {
    ("init", "0"): ("init", "1", "R"),
    ("init", "1"): ("init", "0", "R"),
    ("init", " "): ("final", " ", "N"),
}

t = TuringMachine(
    "010011 ", final_states=["final"], transition_function=transition_function
)

print("Input on Tape:")
print(t.get_tape_str())

while not t.final():
    t.step()

print("Result of the Turing machine calculation:")
print(t.get_tape_str())