Week 28 · Unit 12: Be a problem solver · 3 lessons
2
Counting the seconds
Computing 5: Unit 12, pp. 159–170
GoalWork out how long a route takes when forward moves and turns cost different times, and pick the quickest route.
New words
route · the path that something takes from the start to the endturn · a quarter turn to the left or to the right on the spottime cost · the number of seconds that a step takesfloor robot · a small robot that follows commands on the floor
Explanation
A floor robot follows commands one at a time. Each command takes some time. In this lesson a forward move takes 2 seconds, and a left or right turn takes 3 seconds. To find the time of a route, count the forward moves and the turns. Then work out forwards × 2 + turns × 3. Two routes can end at the same square but take different times. The route with fewer turns is often quicker, even when it is not shorter. An efficient algorithm is the one with the lowest total time.
Command
Time
F (forward one square)
2 seconds
L (turn left)
3 seconds
R (turn right)
3 seconds
Worked examples
The robot starts at the bottom-left square, facing up. It must reach the flower. Route A: F, F, R, F, F, F. It has 5 forwards and 1 turn, so the time is 5 × 2 + 1 × 3 = 13 seconds.
Route B goes up and across in a zigzag: F, R, F, L, F, R, F, F. It has 5 forwards and 3 turns, so the time is 5 × 2 + 3 × 3 = 19 seconds. Route B ends at the same flower, but it takes 6 seconds longer.
Route
Forwards
Turns
Time
A: F F R F F F
5
1
13 s
C: R F F F L F F
5
2
16 s
B: F R F L F R F F
5
3
19 s
Here are three routes to the flower. All of them use 5 forward moves, but the turns are different. The quickest route is the one with the fewest turns.
Class activity
Floor robot (3 players, chalk or tape, a paper cup as the flower). Mark a grid of squares 5 across and 4 high. One player is the robot and follows spoken commands: F, L or R. The caller says the commands for a route from the start to the cup. A timekeeper adds 2 seconds for each F and 3 seconds for each turn on a score sheet. Try three different routes to the cup. Which one is quickest? Does the shortest-looking route always win?
Practice
1
The robot starts at the top-left square, facing right. Work out the time of this command list: F, F, R, F, L, F, F, F. Forward takes 2 seconds and a turn takes 3 seconds.
There are 6 forwards and 2 turns: 6 × 2 + 2 × 3 = 12 + 6 = 18 seconds.
2
Route P has 7 forwards and 1 turn. Route Q has 5 forwards and 4 turns. Which route is quicker? Show the times.
Route
Forwards
Turns
P
7
1
Q
5
4
Route P: 7 × 2 + 1 × 3 = 17 seconds. Route Q: 5 × 2 + 4 × 3 = 22 seconds. Route P is quicker, even though it has more forward moves.
3
This route is a staircase and takes 17 seconds. Write a faster list of commands that ends on the flower. How long does yours take?
F, F, R, F, F. It has 4 forwards and 1 turn: 4 × 2 + 3 = 11 seconds.
4
Why is the route that looks shortest on the grid not always the quickest?
Turns take longer than forward moves in this robot. A route with fewer turns can be quicker, even if it has more forward moves.