GoalReview following and fixing algorithms, making programs concise, resetting sprites and running scripts together.
New words
trace · to follow a program step by step and write down what happensreset · to put a sprite back to its start place or sizeefficient · doing the job with the fewest steps
Explanation
An algorithm is a list of steps in the right order. We follow it one step at a time to see where it leads. If it goes wrong, we find the wrong step, edit it and test again. An efficient algorithm uses the fewest steps. We join moves that are the same and side by side, and we use a repeat for steps that happen again and again. In Scratch, go to and set size blocks right after the hat reset a sprite. Scripts that start with the same event run together, so we check how long each one takes.
Idea
What we do
follow
do each step in order
fix
find the wrong step, edit it, test again
shorten
join same side-by-side steps, use repeat
reset
go to and set size after the hat
timing
add the waits and glides; add a wait to match
Worked examples
The robot starts at the bottom-right facing up. Algorithm: Move 2 forward. Turn left. Move 2 forward. Turn right. Move 1 forward. It goes up 2, faces left, goes 2 along, faces up again and moves 1 more. It ends at the top, in the third column.
This program has 5 blocks. The four “change x by (15)” blocks are side by side, so they become one block “change x by (60)”. The new program has 2 blocks. It moves the sprite to the same place.
Script A waits 1 second and then glides for 1 second: 2 seconds in all. Script B glides for 2 seconds. Both take 2 seconds, so they finish together.
Class activity
Programmer’s checklist (with a friend): make a checklist on a card with five questions, such as “Did I follow every step?”, “Is there a wrong step?”, “Can I join steps?”, “Did I reset?”, “Do my scripts finish together?” Write a short robot algorithm with one mistake, swap with your friend, and use the checklist to find and fix the mistake.
Practice
1
The robot starts at the bottom-left facing up. Algorithm: Move 2 forward. Turn right. Move 3 forward. Turn left. Move 1 forward. Where does it finish: the flag, the tree or the star?
The flag. It goes up 2, right 3, then up 1, so it ends in the top row.
2
Make this program more concise. How many blocks does your new program have?
when green flag clicked, move (30) steps, wait (1) seconds, move (30) steps. It has 4 blocks (the original had 6). The wait stops the two groups from being joined.
3
A sprite starts at size 100. Each run does this program. What size is it after 3 runs with no reset? What block would fix the problem?
70, because each run takes away 10. Add “set size to (100) %” after the hat block, so it is always 90.
4
Script A takes 3 seconds and script B takes 2 seconds. They start together. Which finishes first, and what should be added to B?
B finishes first. Add “wait (1) seconds” to B, so both take 3 seconds.