3
From algorithm to code
Computing 1: Topic 1.2, pp. 19–32
GoalChange an algorithm in words into code with command cards.
New words
code · instructions in a language a robot understandsalgorithm · steps in words; we change them into code
Explanation
First we plan with words. This is the algorithm. A robot cannot read words. So we change the words into code. Code is a row of command cards. Each step in the algorithm becomes one card. We read the cards in order, from left to right.
Worked examples
Algorithm: forward two steps, turn left, forward three steps. The code is F F L F F F. We press GO at the end.
Algorithm: back two steps, turn right. The code is B B R.
Read this code: B L F. In words: back, turn left, forward.
Class activity
Code translator: one person says an algorithm out loud, such as ‘forward two, turn right, forward one’. The other lays out command cards for it. Check each card, left to right. Then swap and make a new algorithm.
Practice
1
Write the code for: forward two steps, turn right.
F F R.
2
Say this code in words.
Turn right, forward, forward, back.
3
What is the word for instructions a robot understands?
Code.
4
Which way do we read the command cards: left to right or right to left?
Left to right.