-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTurnstile.py
31 lines (29 loc) · 991 Bytes
/
Turnstile.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
class SM:
def start(self):
self.state = self.startState
def step(self, inp):
(s, o) = self.getNextValues(self.state, inp)
self.state = s
return o
def transduce(self, inputs):
self.start()
return [self.step(inp) for inp in inputs]
def run(self, n=10):
return self.transduce([None]*n)
class Turnstile1(SM):
startState = 'locked'
def getNextValues(self, state, inp):
if state == 'locked':
if inp == 'coin':
return ('unlocked', 'enter')
else: # Input == None
return ('locked', 'pay')
if state == 'unlocked':
if inp == 'turn':
return ('locked','pay')
else:
return ('unlocked','enter')
turn = Turnstile1()
print turn.transduce([None, None, 'coin', 'coin', 'turn', 'coin', 'turn', 'turn'])
# It properly work, now if you connect it into a turnstile it will work.
# AWESOME!!!