Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- table = {
- 'q1':{' ': [' ', 1, 'q1'], '1': ['1',1,'q1'], '2':['2', 1, 'q1'], '0':['0', 1, 'q1'], '+':['+', 1, 'q2'], '-':['-', 1, 'q3']},
- 'q2':{'1': ['1', -1, 'q4'], '2': ['2', -1, 'q6']},
- 'q3':{'1': ['1', -1, 'q7'], '2': ['2', -1, 'q9']},
- 'q4':{'0': ['0', -1, 'q5'], '1': ['2', -1, 'q5'], '2': ['0', -1, 'q4'], '+': ['+', -1, 'q4'], ' ': ['1', 0, 'qn']},
- 'q5':{'0': ['0', -1, 'qn'], '1': ['1', -1, 'qn'], '2': ['2', -1, 'qn']},
- 'q6':{'0': ['2', -1, 'q5'], '1': ['0', -1, 'q4'], '2': ['1', -1, 'q4'], '+': ['+', -1, 'q6']},
- 'q7':{'0': ['2', -1, 'q7'], '1': ['0', -1, 'q8'], '2': ['1', -1, 'q8'], '-': ['-', -1, 'q7']},
- 'q8':{'0': ['0', -1, 'q8'], '1': ['1', -1, 'q8'], '2': ['2', -1, 'q8'], ' ': [' ', 1,'q10']},
- 'q9':{'0': ['1', -1, 'q7'], '1': ['2', -1, 'q7'], '2': ['1', -1, 'q8']},
- 'q10':{'0': ['0', 1, 'q10'], '1': ['1', -1, 'q11'], '2': ['2', -1, 'q11'], '-': ['-', 0, 'qn']},
- 'q11':{'0': [' ', 0, 'qn'], ' ': [' ', 0, 'qn']}
- }
- tape = list(input())
- state = 'q1'
- index = 0
- while state != 'qn':
- symbol, diff, state = table[state][tape[index]]
- tape[index] = symbol
- index += diff
- print(''.join(tape))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement