2
Words into code
Computing 1: Topic 1.3, pp. 33–48
GoalChange an algorithm in words into a robot code that works.
New words
algorithm · the plan in wordscode · the same plan as command cards
Explanation
An algorithm tells us the plan in words. Code is the same plan as command cards. Change each step into cards. ‘Forward three’ is three forward cards. A turn is one card. Put clear first and GO last. Trace it to check.
Worked examples
Algorithm: forward two, turn left, forward one. Code: X F F L F GO. The robot goes up two and then left one.
Algorithm: turn right, forward four. Code: X R F F F F GO. The robot goes right along the bottom.
Algorithm: forward three, turn left, forward two, back one. Code: X F F F L F F B GO. The robot ends one square back.
Class activity
Write it twice: write an algorithm in words for the robot to go forward two and turn left. Then write the code cards. Show it to a friend. Do they get the same cards? Check each card against the words.
Practice
1
Write the code for: forward one, turn left, forward two.
X F L F F GO.
2
Say this code in words: X F F R F F GO.
Forward two, turn right, forward two.
3
The robot starts at the bottom right facing up. Code: F F F L F. Where does it end?
In the top row, in the second square from the right. It goes up three, turns left, then forward one.
4
Algorithm: back one, turn right. How many cards (not counting X and GO)?
2 cards: B and R.