Unit 1
Algorithms and recipes
Write exact steps for an everyday job, test them on someone who follows them to the letter, and fix what goes wrong.
Read
The sandwich that went wrong
Tomás wanted to be a robot-maker. So he wrote down how to make a cheese sandwich:
- Put cheese on the bread.
- Put bread on top.
"Perfect!" he said. He gave the note to his dad, who was playing a game. In the game, Dad had to do exactly what the note said, and nothing else.
Dad picked up the whole cheese packet, plastic and all, and put it on the bread. Then he put a second bread on top. Squish!
"That's not what I meant!" cried Tomás.
"It's what you wrote," said Dad, grinning.
Steps that are exact
You already know that a list of exact steps is called an algorithm. A recipe is an algorithm for food. The steps for getting dressed are an algorithm too.
Tomás's algorithm looked fine to him. But he knew what he meant, so his brain filled in the missing parts without telling him. Dad couldn't do that. He only did what was written.
That is why every algorithm needs a test.
Write it, test it, improve it
- Write the steps.
- Test them. Give them to someone, and ask them to follow them exactly. Don't help. Just watch.
- Improve them. Find the step that went wrong and fix it.
- Test again. A fix can make a new problem!
Watch how a careful tester follows a better version of Tomás's algorithm. Each step lights up as it happens.
Even this one is not perfect. Can the tester open the bag? Is the cheese out of its packet? Only a test will tell you.
What a good step looks like
Example. Tomás tests his note and finds three problems. Here is how he fixes them.
What went wrong The fix "Put cheese on the bread": Dad used the whole packet. Say how much and what: "Take 1 slice of cheese out of the packet." The cheese was still inside its packet, so Dad could not take a slice. Add a step: "Open the cheese packet." There was no bread on the plate yet. Add a step at the start: "Take 2 slices of bread and put them on the plate." A good step is:
- small: one thing to do,
- exact: it says which thing and how many,
- in the right order: you can't put cheese on bread that is still in the bag.
A trap to avoid
Be careful: "It makes sense to me, so it must be right." Not so! You wrote the steps, so you know what you meant. Only a test with someone else shows what the steps really say.
And when the test goes wrong, don't blame the tester. The tester did the job well. The algorithm needs fixing.
Try it: Open the sandwich tester. Write an algorithm, run the tester, and fix every problem it finds.
For the grown-up helping
Play the literal tester yourself: do exactly what the note says, and no more, with a straight face. Children find this very funny, and it teaches the lesson better than any explanation. When a test fails, ask "What did I do? What did you want me to do?" and let your child find the step to fix. A first algorithm that fails is a good result, not a bad one. It is how every algorithm gets better.
Lab
The sandwich tester
Build an algorithm from step cards and press Run. The tester follows your steps exactly and tells you where it gets stuck. Write it, test it, improve it, then test it on a second tester.
Your goals
- Write an algorithm that makes a cheese sandwich when the tester follows it exactly.
- Fix an algorithm that someone else wrote after the tester finds the problem.
- Improve an algorithm that worked for one tester so it also works for a tester whose bread bag is tied in a knot.
The interactive lab opens once you register. Register to do this.
Activity
Test your algorithm on a person
Your child writes an algorithm for a small everyday job, tests it on a grown-up or friend who follows it exactly, and improves it. Twenty to thirty minutes, with at least two rounds of testing.
You'll need
- Paper and a pencil
- For the jobs: 4 plastic or paper cups (tower job), or a pair of socks and a pair of shoes (dressing job), or paper and a crayon (drawing job)
Steps
- Pick one job together. Good choices are "Build a tower of exactly 4 cups, standing on the table", "Put a sock and a shoe on one foot", or "Draw a simple house with a door and two windows".
- Your child writes the steps on paper, one per line, and numbers them. Younger children can say the steps while you write them down. Aim for at least 6 steps.
- You are the tester. Read only the paper. Do exactly what each step says, and nothing else. Do not guess what your child meant. Keep a straight face and do not speak, except to say "I don't know how to do that" when a step really doesn't make sense.
- Your child watches and does not help. When you reach a step that goes wrong (or can't be done), stop.
- Together, find the bug. Ask "What did I do? What did you want me to do?" Your child fixes the step on the paper, or adds a missing step.
- Test again from step 1. A fix can cause a new problem, so check the whole list.
- Swap! Your child is the tester for an algorithm you wrote, with at least two things deliberately left out. Does your child follow it exactly?
Safety
- Choose jobs without knives, heat, stairs, water or breakable things.
- Keep cups plastic or paper, and clear the floor so no one trips.
- If you test a sock-and-shoe job, sit down first.
Keeping a log of the activity is for registered learners. Register to do this.
Quick check
Algorithms check
Six questions about writing, testing and improving algorithms.
1.What is an algorithm?
- A list of exact steps that gets a job done
- A kind of computer
- A game you play on a tablet
- A short word for a long word
Choose one
2.Put these steps for putting on a sock and shoe in the right order, first at the top.
- Tie the laces
- Push your foot into the shoe
- Pull a sock onto your foot
Put these in order
3.A tester follows these three steps exactly, but gets stuck at step 2. What step is missing?
- Open the juice carton
- Put the glass in the fridge
- Wash the carton with soap
- Nothing is missing, the tester made a mistake
Choose one
4.Ana wrote an algorithm for feeding the class fish. What is the best way to find out whether it is good?
- Read it again to herself. If it sounds right, it is right.
- Ask a friend to follow it exactly while she watches and does not help.
- Count how many steps it has.
- Make it longer, because longer is always better.
Choose one
5.Which of these steps are too vague for a robot to follow? Pick all that apply.
- Make it tidy
- Take two steps forward
- Do the dishes
- Pick up the red cup
Choose all that apply
6.Kofi's tester followed his steps exactly, but the sandwich had no cheese inside. What should Kofi do?
- Find the step that went wrong, fix the algorithm, and test it again
- Tell the tester they did it wrong
- Do nothing. It was just bad luck
- Ask the tester to go faster next time
Choose one
Answering and checking are for registered learners. Register to do this.
Quick check
New puzzles
Use what you know about testing algorithms in some new places.
1.Ravi wrote "Draw a face" for a friend. The friend drew a sad face with ears. Which new version of the step is the most exact?
- Draw a circle. Draw two dots for eyes near the top. Draw a curve like a smile below them.
- Draw a better face
- Draw a happy face, but quickly
- Draw a face again
Choose one
2.A tester follows an algorithm that has 8 steps. The tester gets stuck at step 5 and has to stop. How many steps did the tester finish?
Answer with a number
3.Put the steps for washing your hands in a sensible order, first at the top.
- Put soap on your hands
- Dry your hands on a clean towel
- Rinse the soap off
- Rub your hands together for 20 seconds
- Wet your hands with water
Put these in order
4.Match what the tester said to the best fix.
- I don't know how to 'tidy up'
- There is no cup to pour into!
- You told me to drink the juice before pouring it!
Match each to: Break the step into smaller, exact steps · Put the steps in the right order · Add a step to get a cup first
Answering and checking are for registered learners. Register to do this.
Activity
Tell it back
Your child explains, in their own words, why an algorithm needs a test. Three minutes.
Steps
- Ask "Tomás wrote 'put cheese on the bread' and his dad put the whole packet on. Whose fault was that?" Listen.
- Ask "How could Tomás find out his steps were not good enough before he gave them to someone?" Let your child answer in their own words.
- Ask "Why is it better to test an algorithm on someone else than to just read it over yourself?"
- Write down what your child says. Do not correct or add to it. If they get stuck, ask about the last algorithm they tested.
Keeping a log of the activity is for registered learners. Register to do this.
Like what you see?
Register for free to answer the quick checks, do the activities and save your work. Your work is saved on your device and syncs to your account.