using a dictionary for an automata in python
#multiple DSA using dictionary
class MapAutomata:
def __init__(self, map, initial):
self.map = map
self.initial = initial
def transition(self, inst):
if inst in self.map:
self.initial = self.map[inst]
else:
return False
""" a = MapAutomata({0:4, 1:2, 2:8}, 8)
=> None
a
=> <MapAutomata object at 0x7f82c4dcdc88>
a.initial
=> 8
a.transition(1)
=> None
a.initial
=> 2
a.transition(0)
=> None
a.initial
=> 4
"""