SHARE
TWEET

Untitled

ghettodimasta Oct 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. table = {
  2.     'q1':{' ': [' ', 1, 'q1'], '1': ['1',1,'q1'], '2':['2', 1, 'q1'], '0':['0', 1, 'q1'], '+':['+', 1, 'q2'], '-':['-', 1, 'q3']},
  3.     'q2':{'1': ['1', -1, 'q4'], '2': ['2', -1, 'q6']},
  4.     'q3':{'1': ['1', -1, 'q7'], '2': ['2', -1, 'q9']},
  5.     'q4':{'0': ['0', -1, 'q5'], '1': ['2', -1, 'q5'], '2': ['0', -1, 'q4'], '+': ['+', -1, 'q4'], ' ': ['1', 0, 'qn']},
  6.     'q5':{'0': ['0', -1, 'qn'], '1': ['1', -1, 'qn'], '2': ['2', -1, 'qn']},
  7.     'q6':{'0': ['2', -1, 'q5'], '1': ['0', -1, 'q4'], '2': ['1', -1, 'q4'], '+': ['+', -1, 'q6']},
  8.     'q7':{'0': ['2', -1, 'q7'], '1': ['0', -1, 'q8'], '2': ['1', -1, 'q8'], '-': ['-', -1, 'q7']},
  9.     'q8':{'0': ['0', -1, 'q8'], '1': ['1', -1, 'q8'], '2': ['2', -1, 'q8'], ' ': [' ', 1,'q10']},
  10.     'q9':{'0': ['1', -1, 'q7'], '1': ['2', -1, 'q7'], '2': ['1', -1, 'q8']},
  11.     'q10':{'0': ['0', 1, 'q10'], '1': ['1', -1, 'q11'], '2': ['2', -1, 'q11'], '-': ['-', 0, 'qn']},
  12.     'q11':{'0': [' ', 0, 'qn'], ' ': [' ', 0, 'qn']}
  13. }
  14.  
  15. tape = list(input())
  16. state = 'q1'
  17. index = 0
  18. while state != 'qn':
  19.     symbol, diff, state = table[state][tape[index]]
  20.     tape[index] = symbol
  21.     index += diff
  22. print(''.join(tape))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top