Becoming a better problem solver through BrainF**k part 1: What is BrainF**k?

# See all 4 tutorials!

## Introduction

BrainF**k is called an "esoteric langeuge" because it is technically a programming language but it isn't widely used due to the way it is designed. BrainF**k is one of the earliest and most famous esoteric languages namely because of its simplicity.

BrainF**k works along a "strip" of memory---basically, there are an infinite number of "cells" in a row that you can move forward and backward through. BrainF**k interpreters only recognize 8 symbols, as follows:

symbolmeaning
`+`add one to the current cell's value
`-`subtract one from the current cell's value
`>`move to the right by one cell
`<`move to the left by one cell
`,`take the input (one character of it) and put it in the current cell
`.`print out the ASCII character associated with the current cell's value
`[`If the current cell is zero, skip to the matching `]`
`]`If the current cell is not zero, go back to the matching `[`

Those last two may be the most confusing, but they are essentially how BrainF**k makes decisions, which makes it Turing Complete and allows it to become a programming language. They can be simplified by thinking of `[...]` as a loop, as we will see with our first BrainF**k program, but, as we will learn later on, that will not always be the case.

## Hello, World!

Let's write our first program. Actually, instead of making it say "Hello, World!" let's just make it say "Hi" for now. To make BrainF**k output a letter, you have to know the ASCII number associated with that letter. You can use a table like the one below to do so. In it, we can see that "H" is 72 and "i" is 105. First, here is an example program without loops:

``````++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ add 72 into the current cell (BrainF**k ignores anything but the seven symbols)
. print out H
+++++++++++++++++++++++++++++++++ add another 33 to get 105
. print out i``````

Obviously, though, this approach is tedious. So, let's look at how we can improve our method, using loops! Before we start, know that 72 is 9 8, and 33 is 3 11

``````> move into the second cell
[
< move back into the first cell
> move to the second cell again
- subtract one
] with these square brackets, eight will be added to the first cell nine times until the second cell reaches zero(comma) at which point BrainF**K will continue executing code
< move back into the first cell
. print "H"
> move to the second cell