New paste Repaste Download
table = {
    ('q0', '0', 'z'): ('q0', '0z'),
    ('q0', '0', '0'): ('q0', '00'),
    ('q0', '1', '0'): ('q1', ''),
    ('q1', '1', '0'): ('q1', ''),
    ('q1', '', 'z'): ('q2', 'z'),
    ('q2', '', 'z'): ('q2', 'z'),
}
stack = ['z']
s = input("Type the string\n")
curr = ['q0', '', '']
final = {'q2'}
for ch in s + '':
    top = stack.pop()
    curr[1], curr[2] = ch, top
    if  tuple(curr) not in table:
        print(f"Rejected at state: {curr}")
        exit()
    next = table[tuple(curr)[0]]
    stack.extend(reversed(table[tuple(curr)[1]]))
    curr[0] = next
print("Accepted" if curr[0] in final else "Rejected")
Filename: None. Size: 655b. View raw, , hex, or download this file.

This paste expires on 2025-01-23 06:13:49.666752. Pasted through web.