Multiplication loops
Make a big number from small ones. A loop that runs a times and adds b each time leaves a times b.
●○○ easy · where to see it
The idea
brainfuck can only add 1. To reach 65 you could write 65 plus signs. A loop is shorter. Put 8 in a counter cell, and on each pass add 8 to the next cell and take 1 from the counter.
Read the story
When the counter reaches 0, the next cell holds 8 times 8. This is how almost every brainfuck Hello World builds its letters.
Step by step in brainfuck
The outer loop runs 5 times.
8 times 8, plus 1
Expected output
A
Output
- Counter: cell 0 = 8.
- Each pass:
>++++++++<-adds 8 to cell 1, then takes 1 from cell 0. - After the loop: cell 1 = 64.
>+.prints 65, the letter A.
Nested: 5 times 5 times 2
The outer loop runs 5 times. Each time it puts 5 in cell 1, and the inner loop turns that 5 into 10 in cell 2. Cell 2 ends at 50, the character 2.
Expected output
2
Output
Side by side
Eight i make 8.
The kernel has MUL
Expected output
A
Output
Befunge has *
Expected output
A
Output
Deadfish can only square
Eight i make 8. s squares it to 64, i adds one. Deadfish prints numbers, not letters, so this prints 65.
Expected output
65
Output
Where it appears
- The Hello World on the brainfuck page uses one nested multiplication loop for all its letters.
- Golfed brainfuck builds text from multiplication loops; a golfed
Hello, World!takes 111 commands.