[ create a new paste ] login | about

Link: http://codepad.org/PEdQkG9M    [ raw code | output | fork ]

Lua, pasted on Jan 18:
r=[[S1 s2
S1 0 s2
S1 1 S1
s2 0 S1
s2 1 s2
1001010]]
--r='S1 s2\nS1 0 s2\nS1 1 S1\ns2 0 S1\ns2 1 s2\n1001010'
--r=...
p=print
M={}
s=nil
g=string.gmatch
for w in g(r,'%a%d')do
M[w]={}
s=s or w
end
for i,n,o in g(r,'(%a%d)%s(%d)%s(%a%d)')do
M[i][n]=o
end
for c in g(r:match('%d%d+'),'(%d)')do
z=s
s=M[z][c]
p(z,c,'->',s)
end
p(s==s:upper()and'ACCEPT'or'REJECT')


Output:
1
2
3
4
5
6
7
8
S1	1	->	S1
S1	0	->	s2
s2	0	->	S1
S1	1	->	S1
S1	0	->	s2
s2	1	->	s2
s2	0	->	S1
ACCEPT


Create a new paste based on this one


Comments: