The crew lines up in a narrow tunnel to board the shuttle. Rocket is at the front.
"How many people are behind me?" he wonders. He cannot turn around in the tight tunnel.
Raven is just behind him. "What do you notice? Each person can only see the person right behind them."
Rocket grins. "So I ask you, and you ask the next person?"
Nova glows at the back. "Here is a hint. Someone at the end must answer without asking anyone."
Rocket asks Ada, "How many people are behind you?" Ada cannot see, so she asks Ben the same question.
The question travels back down the line. Dee is last, so Dee answers 0 without asking anyone.
Then each person adds 1 to the answer they heard. They pass the new number forward.
| Person | Asks | Hears back | Says forward |
|---|---|---|---|
| Rocket | Ada | 3 | (knows 4 are behind him) |
| Ada | Ben | 2 | 3 |
| Ben | Cy | 1 | 2 |
| Cy | Dee | 0 | 1 |
| Dee | nobody | 0 |
Every person follows the same rule: ask the person behind, then add 1. Only Dee does something different. Dee is the stopping point.
Now eight crew members stand behind Rocket. Each one follows the same rule as before. Ask the person behind you, then add 1.
| Statement | True or false? |
|---|---|
| Questions travel toward the back of the line. | ? |
| The first answer comes from Rocket. | ? |
| Each answer is 1 more than the answer just behind it. | ? |
| If nobody stops the questions, no answer ever comes back. | ? |
Nice work! Questions going back and answers coming forward is exactly how recursion runs in code. Tomorrow we write our first recursive function.