[ create a new paste ] login | about

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

Lua, pasted on Jan 19:
r=[[S1 s2
S1 0 s2
S1 1 S1
s2 0 S1
s2 1 s2
10X]]
--r='S1 s2\nS1 0 s2\nS1 1 S1\ns2 0 S1\ns2 1 s2\n1001010'
--r=...
p=print

M={}
s=r:match('(%a%d)')
for i,n,o in r:gmatch('(%a%d)%s(%d)%s(%a%d)')do
M[i]=M[i]or{}
M[i][n]=o
end
for c in r:match('%d%d+'):gmatch('(%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
S1	1	->	S1
S1	0	->	s2
REJECT


Create a new paste based on this one


Comments: