Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- memory = list(input())
- idx = 0
- q = 'q1'
- states = [q]
- R, L, N = 1, -1, 0
- table = {'q1': {'0': ['0', R, 'q1'], '1': ['1', R, 'q1'], '2': ['2', R, 'q1'], '+': ['+', R, 'q2'],
- '-': ['-', R, 'q3'], ' ': [' ', R, 'q1']},
- 'q2': {'0': ['0', N, 'qT'], '1': ['1', L, 'q4'], '2': ['2', L, 'q5']},
- 'q3': {'0': ['0', N, 'qT'], '1': ['1', L, 'q6'], '2': ['2', L, 'q8']},
- 'q4': {'0': ['1', N, 'qT'], '1': ['2', N, 'qT'], '2': ['0', L, 'q4'], '+': ['+', L, 'q4'],
- ' ': ['1', N, 'qT']},
- 'q5': {'0': ['2', N, 'qT'], '1': ['0', L, 'q4'], '2': ['1', L, 'q4'], '+': ['+', L, 'q5']},
- 'q6': {'0': ['2', L, 'q7'], '1': ['0', N, 'qT'], '2': ['1', N, 'qT'], '-': ['-', L, 'q6']},
- 'q7': {'0': ['2', L, 'q7'], '1': ['0', L, 'q9'], '2': ['1', N, 'qT'], ' ': [' ', N, 'qT']},
- 'q8': {'0': ['1', L, 'q7'], '1': ['2', L, 'q7'], '2': ['0', N, 'qT'], '-': ['-', L, 'q8']},
- 'q9': {'0': ['0', N, 'qT'], '1': ['1', N, 'qT'], '2': ['2', N, 'qT'],
- ' ': [" ", R, 'q10']},
- 'q10': {'0': [' ', N, 'qT']}}
- while q != 'qT':
- sym, move, state = table[q][memory[idx]]
- memory[idx] = sym
- idx += move
- q = state
- states.append(q)
- for i in memory[:-1]:
- print(i, end='')
- print(memory[-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement