🧠
Day 2 of 5

Think

Write one program that can solve a maze it has never seen before.

Today you will

Level up your brain

New power · Level 10

Repeat 🔁

Instead of five blocks…

forward forward forward forward forward

…use one loop:

repeat 5 { forward }
Repeat lesson
CodeLab · “3 · Repeat”

New power · Level 15

Sense — the robot reacts

Now the robot can make a decision from what it senses:

if wall if pit until goal

if = react once. until = keep going until it's true.

Sensing blocks
if / until blocks

Build this

The wall-follower

repeat until goal { if wall { turn left } forward }

“If there's a wall ahead, turn the same way; otherwise step forward.”

Wall-follower in the editor
In the real editor

The magic ✨

Same program. Mazes it's never seen.

Don't change a single block — run it on a brand-new maze. It still solves it!

Why? Because it's a rule, not a memorised path.

One program, many mazes
One rule → many mazes

Add one rule

Handle pits too

repeat until goal { if wall { turn left } if pit { jump } forward }

A complete, general maze robot in 3 rules.

top
top
scrolled
scroll ↓

We measured it — 16 mazes it had never seen

A rule beats a memoriser

RobotSolved (unseen mazes)
Wall-follower + jump (3 rules)8 / 16
Plain wall-follower (no pit rule)5 / 16
A brain trained on one maze1 / 16

The brain memorised its one maze and gets lost everywhere else. (We'll fix that on Day 4 — train it on lots of mazes.)

New power · Level 20

Functions — name & reuse

Bundle steps under a name and call it whenever you need it. Your program gets shorter and clearer.

CodeLab menu
CodeLab · “5 · Functions”

Big question 💭

“Could this program solve a maze you've never opened? Why?”

Say it back in your own words. That “why” is the whole idea of an algorithm.

You did it 🎉

Day 2 checkpoint

Next time → ⚔️ Day 3: Compete. Hand-code a fighter and a striker in the Arena.

‹ All days