Here’s the bug
A Forward step is missing. It should come after step 4. Without it, Beep turns too early.
Did you find a different fix that also gets Beep to the battery? That counts too! There is often more than one way to fix a bug. The important thing is that you tested it step by step.

The fixed program
- Turn right
- Forward
- Forward
- Turn right
- Forward
- Forward
- Forward
- Forward
What the buggy program did
Here is what happens if Beep follows the program with the bug, step by step. Beep doesn’t bump into anything, but ends up in the wrong square.
| Step | Command | Beep is now at | Facing | Note |
|---|---|---|---|---|
| 1 | Turn right | column 3, row 1 | right | |
| 2 | Forward | column 4, row 1 | right | |
| 3 | Forward | column 5, row 1 | right | |
| 4 | Turn right | column 5, row 1 | down | |
| 5 | Forward | column 5, row 2 | down | |
| 6 | Forward | column 5, row 3 | down | |
| 7 | Forward | column 5, row 4 | down |
Check it with Python
This Python program pretends to be Beep. It follows the fixed program and checks for walls on the way. In Python, squares are counted from 0, so column 1, row 1 is (0, 0).
program = "RFFRFFFF"
walls = [(1, 2), (1, 3), (1, 4), (2, 4), (3, 4)]
width, height = 6, 5
x, y, facing = 2, 0, "up"
moves = {"up": (0, -1), "right": (1, 0), "down": (0, 1), "left": (-1, 0)}
turn_left = {"up": "left", "left": "down", "down": "right", "right": "up"}
turn_right = {"up": "right", "right": "down", "down": "left", "left": "up"}
for step in program:
if step == "F":
dx, dy = moves[facing]
if (x + dx, y + dy) in walls or not (0 <= x + dx < width and 0 <= y + dy < height):
print("Bump! Beep hit a wall at", (x, y))
break
x, y = x + dx, y + dy
elif step == "L":
facing = turn_left[facing]
elif step == "R":
facing = turn_right[facing]
print("Beep finished at", (x, y), "facing", facing)
When you run it, it prints:
Beep finished at (4, 4) facing down
The battery is at (4, 4) in Python’s counting, so Beep made it! Try putting the buggy program, "RFFRFFF", back in and see what Python says.