Lesson 2
Moving the brainfuck pointer
> moves the pointer one cell right, < one cell left. Each cell keeps its value while the pointer is elsewhere, so cells serve as variables.
The lesson
The example reads two bytes into two cells and prints them in the order it read them.
Brainfuck has its own page, and Run opens this example in the editor.
Example
Output
Exercise 1
Read two bytes and print them swapped (ab becomes ba).
Run tries your program on the input below. Check runs it on every test.
| Input | Expected output |
|---|---|
ab | ba |
Hi | iH |
12 | 21 |
Output
A hint
Read both first, then print the second cell before the first.
One answer
Answer: Read two bytes and print them swapped (ab becomes ba).
Expected output
ba
| Input | Expected output |
|---|---|
ab | ba |
Hi | iH |
12 | 21 |
Output
Exercise 2
Read three bytes and print them in reverse order.
Run tries your program on the input below. Check runs it on every test.
| Input | Expected output |
|---|---|
abc | cba |
cat | tac |
123 | 321 |
Output
A hint
Three cells. Fill them going right, print them going left.
One answer
Answer: Read three bytes and print them in reverse order.
Expected output
cba
| Input | Expected output |
|---|---|
abc | cba |
cat | tac |
123 | 321 |
Output