We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Brainfuck in Python

From Esolang
Jump to navigation Jump to search

It is possible to emulate Brainfuck in Python.

Code:

##### Initialization. #####
array = [0 for i in range(32767)] # 32k RAM.
current_value = 0 # Pointer for array.
##### Actual code. #####

# Your commands here... #

To make the > command, do the following:


if current_value == 32767: # Wrap
    current_value = 0
else:
    current_value += 1 # Move right

To make the < command, do the following:


if current_value == 0: # Wrap
    current_value = 32767
else:
    current_value -= 1 # Move left

To make the + command, do the following:


if array[current_value] == 255: # Wrap
    array[current_value] = 0
else:
    array[current_value] += 1 # Increment

To make the - command, do the following:


if array[current_value] == 0: # Wrap
    array[current_value] = 255
else:
    array[current_value] -= 1 # Decrement

To make the , command, do the following:


array[current_value] = ord(input(' Enter exactly ONE character... >')) # Ask for input

To make the . command, do the following:


print(end=chr(array[current_value])) # Prints it out

To make the [ command, do the following:


while array[current_value] != 0: # Opens a loop

Also indent the items below.

To make the ] command, remove one layer of indentation.