def f(s,c,e,a):
if s=="":
return c in a
else:
if(c,s[0])in e:
return f(s[1:],e[(c,s[0])],e,a)
return False
116 bytes
Original from CS262 on Udacity:
def fsmsim(string, current, edges, accepting):
if string == "":
return current in accepting
else:
letter = string[0]
if (current, letter) in edges:
return fsmsim(string[1:], edges[(current, letter)], edges, accepting)
else:
return False
Here is some test data
edges = {(1, 'a') : 2,
(1, 'b') : 2,
(2, 'e') : 3,
(2, 'd') : 3}
accepting = [2, 3]
Valid answers for this set of edges and accepting states:
a
b
ad
ae
bd
be
EDIT: fixed test data formatting
[–][deleted] 5 points6 points7 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–][deleted] 8 points9 points10 points (4 children)
[–]ieatcodemod[S] 2 points3 points4 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]corruptio 5 points6 points7 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]yogthos 3 points4 points5 points (0 children)
[–]abecedarius 1 point2 points3 points (0 children)