Multiply by nested loops: for each unit of a, add b into result — usually destructive unless copied. Sketch a*b with small numbers first.
Brainfuck Medium · Lesson 1 · On the house
Multiply
Nested addition on the tape. Lesson 1 is free — on the house.
Lessons · Brainfuck Medium · Lesson 1 of 10 · On the house
Multiply
Nested addition on the tape.

Layout needs a, b, result, temps. Restore caller contracts. Byte overflow is real — know domain.
Strength-reduce when factors share structure. Clarity first; golf after tests.
Write the arithmetic in comments: 6*7=42. Prove on paper before glyphs.
Multiply by nested loops: for each unit of a, add b into result, usually destructively unless copied. Sketch a*b with small a and b on paper first.
Cell layout for mul typically needs a, b, result, and temps. Restore what callers expect. Wrap overflow is real on bytes — know your domain.
Strength-reduce repeated addition when factors share structure. Clarity first; micro-golf after tests pass.
Outer loops run while their control cell is nonzero; inner loops must restore pointer contracts the outer loop expects. Nested multiply patterns build large constants fast. Draw both control cells.
Each nesting level needs a clear home pointer invariant. If the inner loop exits on the wrong cell, the outer test is wrong and chaos follows. Comment invariants above each bracket pair.
Start with one nesting level for constants, then two when building several cells like Hello. Depth without legends is how experts still get lost.
Build constants with factor loops: nested increments beat unary pluses for large ASCII. Factor 10*7+2 style thinking maps to nested brackets. Keep a working note of the math beside the code.
Verify constants by emitting once in a harness. Off-by-one is the eternal tax. Reuse built constants across letters when relative gaps are small.
Trade length for clarity while learning; golf later. A constant you cannot explain is a constant you cannot fix.
Deepening mul (1): pin down input cells, output cells, and pointer home for this idiom. Write those three facts above the still. Trace values 1 and 2 until the postcondition is obvious without an interpreter.
Workbench on mul (2): every bracket is a while on a named cell. Name the control cell; drive it to zero on purpose. Infinite loops usually mean pointer drift. Re-balance moves before new arithmetic.
Portability for mul (3): document cell width, EOF, and left-edge assumptions in a header. Fixtures that need wrap fail on unbounded cells. Add a probe still for the dialect you wrote against.
Composition for mul (4): after the happy path, force failure modes — wrong home, off-by-one, unbalanced moves — and catalog symptoms. Recognition beats restarting from blank paper in larger katas.
Reading mul (5): rewrite the still with spaces and English labels, then densify again. Accidental plus or bracket characters in labels teach comment hygiene the hard way.
Assessment for mul (6): predict a tape after a short run, or name which cell a loop tests. If you can teach the still with a five-cell diagram in two minutes, you can pass the lesson cleanly.
Invariant for mul (7): state precondition and postcondition as cell equalities plus a pointer index. If either side is vague, the idiom is not ready to nest.
Numeric drill on mul (8): pick three small inputs and fill a table of resulting tapes by hand. Tables catch wrap mistakes a single example hides.
Naming for mul (9): rename cells to role words in comments — counter, acc, temp, flag, src, dst. Update when roles rotate; stale names lie.
Bracket hygiene for mul (10): indent bodies even though whitespace is ignored. Match pairs with a stack while reading dense one-liners.
Emit-as-debug for mul (11): park known letter emits at phase boundaries while building; remove markers when fixtures pass.
Stop condition for mul (12): say what makes the loop end. If you cannot, you do not control it. Zero is native false — design for it.
Caller contract for mul (13): document clobbered cells and final pointer home like an ABI. Ignoring ABI creates heisenbugs across katas.
Minimal still for mul (14): delete commands until the teaching point breaks, then put one back. Remember the minimal still, not the longest golf.
Edge cases for mul (15): try zero inputs, try one, try a value near 255 on byte cells. Boundaries reveal wrap and loop mistakes early.
Refactor note for mul (16): after it works, rename temps and rebalance moves for readability before you nest this idiom inside a larger program.
Teach-back for mul (17): explain the still to an empty chair with only a five-cell diagram. Hesitation marks the exact gap to restudy.
History of practice for mul (20): the first time you get this wrong, write the mistaken tape beside the correct tape. The diff is the lesson. Keep a scrap log of diffs for this topic.
Scaling mul (21): once the tiny example works, scale counters to 5 and 7 before you leap to ASCII sizes. Medium numbers catch off-by-ones without drowning you in pluses.
Interleave for mul (22): alternate one minute of tracing with one minute of typing the still from memory. Retrieval practice beats passive rereading for command sequences.
Negative space for mul (23): list what the idiom does not do — no implicit moves, no implicit clears, no decimal printing. Negatives prevent false expectations.
Fixture seed for mul (24): invent one expected output string or final cell vector. Even a private fixture makes later golf honest instead of theatrical.
Pointer chant for mul (25): after each opcode in the still, say the index aloud. Embarrassment is cheaper than an hour lost on a drifted home.
Algebra ban for mul (26): do not commute moves past mutations on paper. Expand, then simplify only with a completed trace underneath.
mul
++++++[>+++++++<-]>Counter 6; each pass +7 next door; move to 42 — ASCII star.
Quiz
6*7 in neighbor?
Quiz
Preserve factors?
Quiz
Overflow risk?
Quiz
Comment the math?
Quiz
Temps needed?
Quiz
Golf mul when?
Check
Type 6*7 still.
Next: compare values with zero/nonzero flags.
Open-book: the answers are on this page. Pass every quiz and check (7) to mark the lesson done. This visit: 0/7.