-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
34 lines (24 loc) · 958 Bytes
/
index.py
File metadata and controls
34 lines (24 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from machine import TuringMachine
class Main:
def __init__(self):
self.initial_state = "init"
self.accepting_states = ["final"]
self.transaction = {
("init","0"):("init", "1", "R"),
("init","1"):("init", "0", "R"),
("init"," "):("final"," ", "N"),
}
self.final_states = {"final"}
def run(self) -> None:
numbers = input("Binary numbers for the machine: ")
for number in numbers:
if number != "0" and number != "1":
print(f"Enter only binary base numbers!")
return
turing = TuringMachine(numbers, initial_state = "init", final_states = self.final_states, transaction = self.transaction)
print(f"Input on Tape: {turing.getTape()}")
while not turing.final():
turing.step()
print(f"Result of the turing machine calculation: {turing.getTape()}")
go = Main()
go.run()