SHARE
TWEET

Untitled

a guest Jan 8th, 2020 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. s = input()
  2. field = [0] * 30000
  3. i_cur = 0
  4. cycled_b = list()
  5. i = 0
  6. ignore = False
  7. ignore_item = 0
  8. while i < len(s):
  9.     elem = s[i]
  10.     if cycled_b and elem == ']':
  11.         if ignore and cycled_b[-1] == ignore_item:
  12.             ignore = False
  13.             continue
  14.         if field[i_cur] != 0 and not ignore:
  15.             i = cycled_b.pop() - 1
  16.         else:
  17.             cycled_b.pop()
  18.     elif elem == '>' and not ignore:
  19.         i_cur = (i_cur + 1) % 30000
  20.     elif elem == '<' and not ignore:
  21.         i_cur = (i_cur - 1) % 30000
  22.     elif elem == '+' and not ignore:
  23.         field[i_cur] = (field[i_cur] + 1) % 256
  24.     elif elem == '-' and not ignore:
  25.         field[i_cur] = (field[i_cur] - 1) % 256
  26.     elif elem == '.' and not ignore:
  27.         print(field[i_cur])
  28.     elif elem == '[':
  29.         cycled_b.append(i)
  30.         if field[i_cur] == 0 and not ignore:
  31.             ignore_item = i
  32.             ignore = True
  33.     i += 1
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
Top