1
Follow the path
Computing 2: Unit 1, pp. 8–23
GoalWrite an algorithm for a path on a grid by counting the squares in each straight part.
New words
path · the way from one place to anothergrid · a pattern of squaressquare · one box of the grid; a character moves one square for each number
Explanation
A path is the way from one place to another. On a grid, we count squares. To write an algorithm for a path, follow it and count the squares in each straight part. Each time the path turns, we need a new step. The path in the picture goes up 2 and then right 4. The character moves one square for each number.
Worked examples
The same path as blocks. The first block goes up 2. The second block goes right 4.
A path with three straight parts: right 2, down 2, right 3. The algorithm is: start, right 2, down 2, right 3, stop.
Count the moves, not the squares you stand on. If you start in square 1 and finish in square 4 on the same row, you made 3 moves.
Class activity
Paper grid game (two players): draw a grid of 6 squares across and 5 squares down. Put a coin on one square for the start and draw a star on another square. Write an algorithm of two or three move steps, such as right 2, up 3. Your friend moves the coin along your steps. Does it land on the star? If not, find the step that is wrong and fix it.
Practice
1
Write the algorithm for this path. Start, ?, ?, stop.
Move right 3, then move up 2.
2
The algorithm says: right 2, up 3, right 2. Does it match the path? What must change?
No. The path goes up 2, so up 3 must change to up 2.
3
How many squares does the character move in all?
3 + 4 = 7 squares.
4
A path has three straight parts. How many move blocks does the program need?
Three, one for each straight part.