Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."
- program_index = 0
- data = []
- for i in range(0, 30000):
- data.append(0)
- data_index = 0
- while program_index < len(program):
- command = program[program_index]
- if command == '>':
- data_index += 1
- elif command == '<':
- data_index -= 1
- elif command == '+':
- data[data_index] += 1
- elif command == '-':
- data[data_index] -= 1
- elif command == '.':
- print(chr(data[data_index]))
- elif command == ',':
- user_input = ord(raw_input()[0])
- data[data_index] = user_input
- elif command == '[':
- if data[data_index] == 0:
- nesting_counter = 0
- while nesting_counter > 0 or program[program_index] != ']':
- if program[program_index] == '[':
- nesting_counter += 1
- elif program[program_index] == ']':
- nesting_counter -= 1
- program_index += 1
- elif command == ']':
- if data[data_index] != 0:
- nesting_counter = 0
- program_index -= 1
- while nesting_counter > 0 or program[program_index] != '[':
- if program[program_index] == ']':
- nesting_counter += 1
- elif program[program_index] == '[':
- nesting_counter -= 1
- program_index -= 1
- program_index += 1
- print('Program complete.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement