Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- userCode = input("Enter your BrainFuck: ")
- print('\n', userCode)
- #print(userCode[0])
- dataPoint = 0
- userData = [0]*2000
- n = 0
- while n < len(userCode):
- uC = userCode[n]
- #print(n, uC)
- if uC == '>':
- dataPoint = dataPoint + 1
- n = n + 1
- continue
- elif uC == '<':
- dataPoint = dataPoint - 1
- n = n + 1
- continue
- elif uC == '+':
- userData[dataPoint] = userData[dataPoint] + 1
- n = n + 1
- continue
- elif uC == '-':
- userData[dataPoint] = userData[dataPoint] - 1
- n = n + 1
- continue
- elif uC == '.':
- print(chr(userData[dataPoint]),end='')
- n = n + 1
- continue
- elif uC == '[':
- if userData[dataPoint] <= 0:
- a = 1
- x = userCode[n + a]
- while x != ']':
- a = a + 1
- x = userCode[n + a]
- n = n + a + 1
- else:
- n = n + 1
- continue
- elif uC == ']':
- if userData[dataPoint] > 0:
- a = 1
- x = userCode[n - a]
- while x != '[':
- a = a + 1
- x = userCode[n - a]
- #print('i found ', x, ' at ',(n-a))
- n = n - a + 1
- else:
- n = n + 1
- continue
- else:
- n = n+1
- print("\nDone")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement