Advertisement
Guest User

BrainFuckery

a guest
Feb 26th, 2013
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. userCode = input("Enter your BrainFuck: ")
  2. print('\n', userCode)
  3. #print(userCode[0])
  4. dataPoint = 0
  5. userData = [0]*2000
  6. n = 0
  7. while n < len(userCode):
  8.     uC = userCode[n]
  9.     #print(n, uC)
  10.     if uC == '>':
  11.         dataPoint = dataPoint + 1
  12.         n = n + 1
  13.         continue
  14.     elif uC == '<':
  15.         dataPoint = dataPoint - 1
  16.         n = n + 1
  17.         continue
  18.     elif uC == '+':
  19.         userData[dataPoint] =  userData[dataPoint] + 1
  20.         n = n + 1
  21.         continue
  22.     elif uC == '-':
  23.         userData[dataPoint] =  userData[dataPoint] - 1
  24.         n = n + 1
  25.         continue
  26.     elif uC == '.':
  27.         print(chr(userData[dataPoint]),end='')
  28.         n = n + 1
  29.         continue
  30.     elif uC == '[':
  31.         if userData[dataPoint] <= 0:
  32.             a = 1
  33.             x = userCode[n + a]
  34.             while x != ']':
  35.                 a = a + 1
  36.                 x = userCode[n + a]
  37.             n = n + a + 1
  38.         else:
  39.             n = n + 1
  40.         continue
  41.     elif uC == ']':
  42.         if userData[dataPoint] > 0:
  43.             a = 1
  44.             x = userCode[n - a]
  45.             while x != '[':
  46.                 a = a + 1
  47.                 x = userCode[n - a]
  48.                 #print('i found ', x, ' at ',(n-a))
  49.             n = n - a + 1
  50.         else:
  51.             n = n + 1
  52.         continue
  53.     else:
  54.         n = n+1
  55. print("\nDone")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement