SoftwareLab 2: I got some guidance from https://tetriminos.wordpress.com/category/education/mit-ocw/6-01-introduction-to-eecs-i/
################################## # Double Delay SM ################################## class Delay2Machine(sm.SM): def __init__(self, val0, val1): self.startState = (val0,val1) def getNextValues(self, state, inp): return ((state[1],inp),state[0])
class CommentsSM(sm.SM): startState = 'Silent' def getNextValues(self, state, inp): if state == 'Silent': if inp == '#': return ('Echoing',inp) else: return ('Silent',None) else: if inp == '\n': return ('Silent', None) else: return ('Echoing', inp)
class FirstWordSM(sm.SM): startState = 'Start_of_Line' def getNextValues(self, state, inp): if state == 'Start_of_Line': if inp!= '\n' and inp !=' ': return ('Echoing',inp) else: return ('Start_of_Line',None) elif state == 'Echoing': if inp == '\n': return ('Start_of_Line', None) elif inp ==' ': return('Silent',None) else: return ('Echoing', inp) else: if inp == '\n': return ('Start_of_Line', None) else: return ('Silent',None)
Join our real-time social learning platform and learn together with your friends!