Today you will write clear steps that cannot be misread, trace them by hand, and find and fix a bug.
builders120 min
How computers work
Algorithms: instructions that cannot be misread
Today you will write clear steps that cannot be misread, trace them by hand, and find and fix a bug.
Story4 min
Teacher block: Ocen cooks the beans
Akello’s mother goes to the market. She leaves a note for Ocen:
“Cook the beans. Put them on the fire. When they are done, take them off.”
Ocen puts the beans on the fire. After five minutes he says, “They look done.” He takes them off.
When Akello’s mother comes home, the beans are hard as stones.
Ocen says:
Ocen says: But you said, when they are done!
“But I thought you would check,” says Akello’s mother.
Whose bug was it? What should the note have said?
Did you know?2 min
Did you know? Where the word algorithm comes from
More than 1,000 years ago, a scholar named Muhammad ibn Musa al-Khwarizmi worked in Baghdad. He wrote a book that showed how to calculate with the numbers 0 to 9, in clear steps, in order. Later the book was translated into Latin in Europe. His name was written as Algoritmi. From it we get the word algorithm. The word algebra comes from the title of another of his books. Every app on your phone follows algorithms.
Why must the steps of an algorithm be clear enough that nobody can misread them?
Remember5 min
Teacher block: Recall from the week
Think. Then show with your fingers.
A computer does exactly what? 1. What you mean 2. What it is told, in order 3. What it guesses
The path is Documents/School/Maths/week1.txt. What is the type of the file? 1. Maths 2. txt 3. School
Which keeps your work when the power goes? 1. Memory 2. Storage 3. Screen
Show your folder tree from the home mission to a partner. Say one path in it. (20 seconds each.)
Learn10 min
Teacher block: What makes a good algorithm
An algorithm is a list of steps that solves a problem. The idea is older than computers. The first computers filled a room. People gave them their steps by moving cables by hand.
Part of ENIAC, one of the first computers (1945). It was as big as a room.Photo: The original uploader was TexasDex at English Wikipedia., CC BY-SA 3.0
A good algorithm is:
Clear. Nobody has to guess. “Cook until done” is not clear. “Press a bean. If it is soft, stop” is clear.
Ordered. The steps are in the right order.
Finite. It ends. It does not go on for ever.
An algorithm is built from three kinds of step:
Sequence. Do the steps one after the other. Wash the beans. Put them in the pot. Add water.
Decision. Choose a path. If a bean is soft, take the pot off. Otherwise, wait.
Repetition. Do something again and again until something happens. Repeat: wait 10 minutes and press a bean. Stop when it is soft.
Here is the bean note as a picture. The diamond asks a question. The arrow that goes back up makes the repetition. Press Walk through to follow it, and choose Yes or No at the question.
Crossing the road: look right and left. If a vehicle is coming, wait. Otherwise walk. Look again at the middle. That is a decision, inside a repetition.
A boda fare (these numbers are an example, not real prices): if the trip is 3 km or less, the fare is 3000 shillings. Otherwise, the fare is 3000 plus 1000 for each extra km. For 5 km: 3000 plus 2 times 1000, so 5000.
No computer8 min
Teacher block: The literal robot
Write the steps to put one spoon of sugar in a cup of water.
You have 3 minutes. Write numbered steps. Use only simple actions.
Then your teacher is the robot. He does exactly what you wrote.
Learn8 min
Teacher block: Tracing with a table
To trace an algorithm is to run it by hand, step by step, and write down what changes. A trace table helps.
Problem: find the largest of three numbers.
Read the numbers a, b and c.
Set biggest to a.
If b is greater than biggest, set biggest to b.
If c is greater than biggest, set biggest to c.
Say the value of biggest.
Trace it with a = 7, b = 12, c = 9.
Step
a
b
c
biggest
Output
1
7
12
9
2
7
12
9
7
3
7
12
9
12
4
7
12
9
12
5
7
12
9
12
12
No computer8 min
Teacher block: Paper exercise, find the bug
Trace and fixName:
1. Trace the largest of three numbers with a = 5, b = 9, c = 7. Fill the table.
Step
a
b
c
biggest
Output
1
2
3
4
5
2. Here is a buggy algorithm for the same job.
Read the numbers a, b and c.
Set biggest to a.
If b is greater than a, set biggest to b.
If c is greater than a, set biggest to c.
Say the value of biggest.
Trace it with a = 5, b = 9, c = 7. What does it say?
What is the bug?
Write the fixed steps 3 and 4.
3. Trace this one. What does it say?
Set total to 0. Set count to 1.
Repeat steps 3 and 4 until count is greater than 4.
Add count to total.
Add 1 to count.
Say total.
4. Cooking rice: the note says “Boil the water. Add the rice. Cook until it is ready.” Write one bug in this note, and say which kind: unclear, missing, wrong order, or never ends.
CheckQuestion 1 of 4
Which is not a property of a good algorithm?
On the computer35 min
Laptop block: Task card, my algorithm
With no teacher. Read the card. Follow it. Ask your partner first.
Your pair: one driver and one navigator. Swap every 10 minutes. If there are 3 of you, one is the timekeeper and joins a pair as a second navigator. Rule: do not change another person’s file.
Before you start: if the Lenovo is off, switch it on. Both of your folders must be on this laptop. If one is missing, make it now with the steps from the Files and folders task card.
Choose your task. Pick one daily task you know well. For example: walk to school, wash clothes, charge a phone and know when to unplug, buy tomatoes at the market, find a boda boda fare. Your algorithm needs 5 to 8 steps, at least one decision (if … otherwise …) and, if you can, one repetition (repeat … until …).
Round 1 (10 minutes): driver one types
Open your folder.
Windows: click the yellow folder icon at the bottom, then Documents, then your name folder, then projects.
Mac: click the Finder icon, then Documents, your name folder, then projects.
Open the text editor. Windows: Start, type Notepad. Mac: Command and Space, type TextEdit, press Return, then Format and Make Plain Text.
Type your algorithm. The first line is the title: for example, Algorithm: boil water for tea. Then numbered steps. One step per line.
Predict first: will a stranger be able to follow your steps without asking you a question?
Save it. Ctrl and S (Windows) or Command and S (Mac). Choose your projects folder. Name it algorithm- plus your task, for example algorithm-tea.txt. Click Save.
The navigator reads each step and asks: clear? ordered? finite?
Swap! Driver two does the same for their own task, in their own projects folder.
Round 2 (10 minutes): driver two types. (Same steps as Round 1.)
Swap!
Round 3 (10 minutes): follow like a robot
Swap with the other pair. The other pair comes to your laptop, and you go to theirs. (If you are only one pair: swap with your partner, and follow their file.)
Open the algorithm file. Follow the path: Documents, then the name folder, then projects, then the file.
One person reads one step aloud and acts it, exactly, like the human robot. Do not guess what the writer meant. If the step is not clear, say “I cannot do that, because …”.
The other person writes the bug on paper using this shape:
Step
What went wrong
Kind (unclear, missing, wrong order, never ends)
Be kind. Say “I found a bug”, not “your steps are bad”.
Last 5 minutes: fix. Take your bug report back. On your laptop, change the step in your file. Save it with Ctrl or Command and S. Rename it to end with -v2 if you changed it (for example algorithm-tea-v2.txt). Leave both laptops on at the end. The Pioneers use them next.
Stuck? Before you ask anyone, try three things:
Read the step again, slowly, out loud.
Ask your partner: “What do you see? Where did we save the file?”
Use the search box in File Explorer or Finder, and type the start of your file name. If it still fails, write the problem on paper and carry on.
Challenge10 min
Laptop block: Challenges
Choose one level. Typing practice is part of every level.
Warm up, everyone (3 minutes). Put the bean steps in order. Use the arrows, or drag a step. Then click Check my order. (No laptop? Number the steps on paper instead.)
Cook the beans
Put the steps in the right order. Use the arrow buttons, or drag a step.
Bronze
In the Key finder, do 2. All letters and 3. Numbers. Then read your own algorithm once more and check it has a title and numbered steps.
Silver
In the Key finder, do 4. My name. Then add one repetition to your algorithm if it has none. It must have a way to stop. Save it again.
Gold
Write a second algorithm: find the largest of three numbers, in your own words, with the trace table for 3, 18 and 11 typed as text. Save it as algorithm-largest.txt in your folder. Then find a bug on purpose, and write which kind it is.
Key finder
Key finder
Key finder
Wan Bene moment10 min
Say it out loud: my bug
Stand up and talk for one minute.
Tell us about one bug in your algorithm that the other pair found. What kind was it? How did you fix it?
Use this shape: My task was … . The bug was in step … . It was an unclear, missing, wrong order or never ending bug. I fixed it by … .
Exit question10 min
Exit question
Show with your fingers.
The note says: “Repeat: add 1 to the count.” It has no stop. What is missing?
It is not clear
It is not ordered
It is not finite
Then say one sentence: “Today I learned that …”
Tick your skills.
Home mission10 min
Home mission
Paper (everyone). Write the steps for your morning, from waking up to leaving home. Include one decision (if … otherwise …) and one repetition (repeat … until …). Ask someone at home to follow your steps exactly. Find one bug. Fix it. Bring your page tomorrow.
Phone (only if a family phone is free, and you have asked). Find one decision your phone makes on its own. For example, a battery warning that comes if the battery is low. Write it as: If … then … otherwise ….