The Rice Runner🏃🏿♂️
Day 9 and it's just before iftar. Mustafa is helping out in the mosque kitchen and will be carrying out food to the members of the community who will be breaking their fast together..
He tucks his trousers into his socks so there’s no chance he will trip, and adjusts his fez one last time.
Uncle Idris hands Mustafa a plate of food and points across the hall.
"Careful now," he says. "Take this to Uncle Jerome."
The hall is already busy. People are seated at tables, chairs are pulled out, and narrow walkways weave between them. Mustafa must carry the plate without spilling a single grain of rice.
There is only one safe route.
The Floor Plan
The mosque hall is represented as a grid.
- Each character represents one square on the floor
- The layout you are given is the exact layout of the hall
Symbols
| Symbol | Meaning |
|---|---|
| S | Mustafa’s starting position |
| G | Uncle Jerome (the goal) |
| . | Empty walkway (safe to walk on) |
| λ | Chair (safe to walk on) |
| # | Table (blocked — cannot be entered) |
Movement Rules
Mustafa must obey all of the following rules:
Mustafa may move one square at a time
He may only move:
Up
Down
Left
Right
Diagonal movement is not allowed
Mustafa may not step onto tables (#)
Mustafa may step onto walkways (.) and chairs (λ)
Mustafa may not leave the bounds of the grid
Mustafa may not step on the same square more than once
The Task
Given the floor plan:
Determine whether Mustafa can reach Uncle Jerome
If he can:
Find the minimum number of steps required to do so
If he cannot:
Return IMPOSSIBLE
Expected Output
Return one value:
The minimum number of steps from S to G, or
IMPOSSIBLE if no valid path exists
Notes
The shortest route is not always the most obvious
Dead ends exist
Some routes appear promising but lead nowhere
Solving this by hand is impractical — careful reasoning or code is advised
Example
S . . #
# λ . #
# λ . G
A valid path exists:
S → . → . ↓
λ ↓
. → G
Total steps: 5