Created
June 1, 2015 16:29
-
-
Save davidwallacejackson/07c8dbce9f41e1bc20cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment