Grades 3–5 · Computing
How can a first mismatch locate an instruction bug?
A bug is a mismatch between intended behavior and what instructions actually produce. The first mismatch shows where a sequence begins to go wrong. This means comparing each resulting state, not just the final square.
In the diagramDebug the first position-or-facing mismatchStart: column 2, row 4, facing N (page-up)12345Goal: (1,2), facing WPlanGivenFLRFirst mismatch: step 3Repair: R → LF moves; L/R turn 90° in place. No sideways moves.
The bot's state includes its position and facing direction. It starts in column 2, row 4 facing north, which means page-up. F moves one square forward in the current direction. L and R turn a quarter-turn in place, leaving the position unchanged.
The intended sequence is F, F, L, F. The given sequence is F, F, R, F. Their first two forward movements agree. The third commands leave the bot on the same square but facing opposite ways: west in the plan and east in the given program.
That facing difference explains why the final forward movement goes the wrong way. Replacing the third R with L restores the intended sequence. Restarting from the original state makes the comparison consistent. A matching endpoint alone would not establish agreement with every intermediate position and facing.
About this explanation
Starting knowledge: Read row and column locations and recognize a quarter-turn while keeping track of a facing direction.
Sources
- University of Canterbury, CS Unplugged — Kidbots: Exact commands, testing and debugging