LearnBrainfuck basics

Reading brainfuck

By the end of this lesson you can read a program somebody else wrote: tell comments from commands, recognise the common pieces, and trace a program by hand.

Comments that bite

This program has a line of explanation above it, and it prints more than the letter H. Press Step a few times and watch which command runs first, then repair the program:

Pieces you know

Here are three short pieces of program, each one you have met before. Choose what each of them does:

Trace it by hand

Work out on paper, without running anything, what cell 1 holds when the program ++[>+++<−]>+ has ended. Type your answer and press Check. A machine then appears to check it with:

A stranger’s program

Here is a program without a word of explanation, with a box for its input. Try a few short inputs and watch the tape, then say what it does:

Check yourself

A free exercise

Take a program you wrote in Lesson 9, give every part its own line and a comment, and check that it still does the same. Nothing is checked here:

For when you need them

Four places that help once you write programs of your own:

What you can do now

You can tell comments from commands, recognise clear, move and copy at a glance, and trace a short program on paper. These are the pieces to recognise:

The pieces of Lesson 10.
PieceWhat it does
[−]Clear: empty the cell.
[−>+<]Move: add the cell to the cell on its right, and empty it.
,[.,]Copy the input to the output.

That was the last lesson of Brainfuck basics. Build toward a chatbot is the next course: it makes brainfuck do real arithmetic, lesson by lesson, towards one number of a chat model.