Brainfuck Interpreter

Your code's output will appear here.
Step speed: Hide steps? ASCII mode?

What is Brainfuck?

Brainfuck is an esoteric programming language, meaning that it's not very useful for any practical purposes, but it can be a great source of programming puzzles. It is an extremely minimalistic cellular automaton, and is meant to be similar to a Turing Machine. A brainfuck-executing machine consists only of a series of cells arranged linearly, each of which can store numerical values, and a pointer that can move between adjacent cells. This system can be programmed using combinations of only eight basic commands:

Surprisingly, this language is Turing-complete, meaning that it can be used to implement any computable function (including any functions that can be implemented in Javascript, Python, or other programming language). However, Brainfuck has also been called a 'Turing tar-pit,' because implementations of more complex programs are extremely cumbersome and complex. Even implementing simple programs can be challenging puzzles.

There are multiple different ways of implementing Brainfuck. This interpreter supports two different versions of Brainfuck: numerical mode and ASCII mode. In numerical mode (the default), input consists of a series of comma-separated numbers, and cells can store any arbitrarily large positive integer value (but cannot go below zero). In ASCII mode, any ASCII string will be accepted as input and the characters are translated into numbers and entered into cells one-by-one, and numerical output is also translated back into ASCII before being displayed. Additionally, since there are only 256 ASCII characters, ASCII mode uses "byte cells" that can only contain integers between 0 and 255. Attempting to decrement 0 will produce an error in numerical mode, but it will "wrap around" to 255 in ASCII mode.

Here are a couple more conventions that this interpreter uses:

Also, be wary of running your Brainfuck code with 'hide steps' turned on. If your code enters an infinite loop, it could temporarily crash the intepreter.

What the heck am I supposed to do with this?

Here are some simple, easy-to-deconstruct programs you can try in numerical mode:

...and here are a few for ASCII mode:

Here are two more complicated examples. The code below (to be run in numerical mode with two cells) prints out the powers of two in increasing order until it either crashes or is aborted:

+[.[->++<]>[-<+>]<]

This code uses 13 cells in ASCII mode to print the text 'BRAINFUCK!'

>++++++++++[[>]+[<]>-]<+++++++++++[->+++<]>[>[++>]<-[<]>-]+++++[>>+++>>+>++>+>++++>>++<<<<<<<<<-]>>+>->++>++>->->+>->[-<]>[.>]

Want to try your hand at writing Brainfuck code? Here are four types of fun challenges you might want to try: