2
Find the wrong step
Computing 3: Unit 1, pp. 8–27
GoalFind the step that makes an algorithm go wrong and edit it so the algorithm works.
New words
edit · to change something so that it is better or correctcorrect · to fix a mistakecheck · to follow an algorithm and see if it does what we wanted
Explanation
Sometimes we follow an algorithm and it does not do what we wanted. It has a mistake. First, follow it and notice where you end up. Then compare that with where you wanted to be. Look at each step. Which step sent you the wrong way, or too far? Change only that step. Then follow the algorithm again to test it. Keep editing and testing until it works.
follow the steps→compare with the goal→edit the wrong step→test again
Worked examples
The robot must reach the flower. The algorithm is: 1 Move 3 squares right. 2 Move 3 squares up. It ends at the top, one square too far. Step 2 is wrong. We edit it to “Move 2 squares up”. Now the robot stops on the flower.
| Step | Instruction |
|---|---|
| 1 | Press 3 |
| 2 | Press − |
| 3 | Press 4 |
| 4 | Press = |
The robot must reach the tent. The algorithm says: 1 Move 2 squares up. 2 Move 2 squares left. After step 1 the robot is at the left edge, so moving left would take it off the grid. The direction in step 2 is wrong. It should say “right”.
Class activity
Be the bug hunter (with an adult): the adult writes a five-step algorithm to get from your bedroom door to a chair in the house, but secretly puts in one wrong number or direction. Follow it with your feet, one step at a time. When you end up in the wrong place, say which step is wrong and how to edit it. Then swap and make a mistake for the adult to find.
Practice
1
The robot should reach the star. The algorithm is: 1 Move 4 squares right. 2 Move 1 square up. Where does the robot end up, and which step is wrong? How do you edit it?
It ends one square too far to the right, next to the star. Step 1 is wrong. It should say “Move 3 squares right”.
2
This algorithm should write the word “sun”. Which steps are wrong? Write the correct algorithm.
| Step | Instruction |
|---|---|
| 1 | Write s |
| 2 | Write n |
| 3 | Write u |
Steps 2 and 3 are in the wrong order. The correct algorithm is: Write s, Write u, Write n.
3
The robot starts in the top-left corner and must reach the tree. The algorithm is: 1 Move 2 squares right. 2 Move 2 squares up. Which step is wrong, and why?
Step 2. The robot is in the top row, so it cannot go up. The tree is below it, so the step should be “Move 2 squares down”.
4
Rosa’s algorithm does not work, so she changes every step. Is that a good plan?
No. She should find the wrong step and change only that one. Then she should test the algorithm again.