-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple_automaton.py
More file actions
30 lines (26 loc) · 816 Bytes
/
Simple_automaton.py
File metadata and controls
30 lines (26 loc) · 816 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
class Automaton(object):
def __init__(self):
self.states = {1:'q1', 2:'q2', 3:'q3'}
self.current = self.states.get(1)
def read_commands(self, commands):
for each in commands:
if self.current == 'q1':
if each == '1':
self.current = 'q2'
else:
continue
elif self.current == 'q2':
if each == '0':
self.current = 'q3'
else:
continue
elif self.current == 'q3':
if each == '1' or each == '0':
self.current = 'q2'
if self.current == 'q2':
return True
else:
return False
# Return True if we end in our accept state, False otherwise
my_automaton = Automaton()
print(my_automaton.read_commands(["1", "0", "0", "1", "0"]))