Lesson 1
Brainfuck's row of cells
Brainfuck has a long row of byte cells, all zero, and a pointer at the first one. Four of its eight commands work on the cell under the pointer.
The lesson
+ adds one to that cell and - takes one away; 255 + 1 wraps to 0. . prints the cell as a byte and , reads one byte of input into it. Everything else in the program is a comment.
The example adds 48, the code of 0, and prints three digits.
Brainfuck has its own page, and Run opens this example in the editor.
Example
Output
Exercise 1
Read one byte and print it back.
Run tries your program on the input below. Check runs it on every test.
| Input | Expected output |
|---|---|
a | a |
Z | Z |
7 | 7 |
Output
A hint
Two commands. One reads, one prints.
One answer
Answer: Read one byte and print it back.
Expected output
a
| Input | Expected output |
|---|---|
a | a |
Z | Z |
7 | 7 |
Output
Exercise 2
Read one byte and print the byte after it (a becomes b).
Run tries your program on the input below. Check runs it on every test.
| Input | Expected output |
|---|---|
a | b |
Y | Z |
0 | 1 |
Output
A hint
Read, add one, print.
One answer
Answer: Read one byte and print the byte after it (a becomes b).
Expected output
b
| Input | Expected output |
|---|---|
a | b |
Y | Z |
0 | 1 |
Output