AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Write it, fix it

Week 20 · Unit 8: Be an artist · 3 lessons
1

Write the algorithm

Computing 2: Unit 8, pp. 106–121
GoalWrite an algorithm for a robot from a picture of the path it must follow.
New words
corner · a place where the path turnsalgorithm · a set of steps, in order, that tells how to do a tasktrace · to follow the steps one by one to see what they do
Explanation

To write an algorithm from a picture, first find the start and the way the robot faces. Next, count the squares in each straight line. At each corner, write turn left or turn right. Put start and marker down at the beginning, and stop at the end. Last, trace your algorithm with a finger to check that it matches the picture.

1 find the start2 count each line3 write each turn4 trace to check
Worked examples
The number 2. The robot starts at the top left, facing right. The first line has 2 squares. At the first corner the path goes down, so the robot turns right.
StepInstruction
1Start
2Marker down
3Forward 2
4Turn right
5Forward 2
6Turn right
7Forward 2
8Turn left
9Forward 2
10Turn left
11Forward 2
12Stop
The algorithm for the 2, written step by step. The turns are right, right, left, left.
How do we know whether to turn left or right? Imagine you are the robot. Here the robot faces right, and the path goes down. Down is on the robot’s right-hand side, so the turn is a turn right. If the path goes to the robot’s left-hand side, turn left.
Class activity

Chalk shapes: with an adult, draw a path on the ground with chalk using straight lines and right-angle turns, or draw one on squared paper. Write an algorithm for it. Swap with a friend. Your friend is the robot and walks your algorithm. Did they walk your shape? If not, find the step that is wrong.

Practice
1
Write the algorithm for this path. The robot starts at the top right, facing left.
2
Write the algorithm for this path. The robot starts at the top left, facing right.
3
In the number 2, the robot faces right and the path goes down at the first corner. Which turn is this?
4
How many steps does the algorithm for the first path in this practice have?