-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (47 loc) · 1.14 KB
/
main.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from tm import *
# TM Example
states = {'q0', 'q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7', 'q8'}
alphabet = {'*', '|'}
its = {
IT('q0', '*', LEFT, 'q1'),
IT('q0', '|', LEFT, 'q0'),
IT('q1', '*', LEFT, 'q2'),
IT('q1', '|', LEFT, 'q1'),
IT('q2', '*', LEFT, 'q2'),
IT('q2', '|', '*', 'q3'),
IT('q3', '*', LEFT, 'q4'),
IT('q3', '|', '|', 'q3'),
IT('q4', '*', HALT, 'q4'),
IT('q4', '|', RIGHT, 'q5'),
IT('q5', '*', RIGHT, 'q5'),
IT('q5', '|', '*', 'q6'),
IT('q6', '*', RIGHT, 'q7'),
IT('q6', '|', '|', 'q6'),
IT('q7', '*', '|', 'q8'),
IT('q7', '|', LEFT, 'q2'),
IT('q8', '*', '*', 'q8'),
IT('q8', '|', HALT, 'q8'),
}
initial_state = 'q0'
initial_configuration = Configuration(
'q0',
Tape(
list('*||*|*'),
0
),
5
)
its_tuple = get_transitions_and_instructions(its)
transitions = its_tuple[0]
instructions = its_tuple[1]
tm = TM(
states,
initial_state,
alphabet,
instructions,
transitions,
initial_configuration
)
# Execute example
result = tm.transitate_until_halt()
print_full_transitions(tm.get_initial_configuration(), result)