Lite / Building Machines That Respond / Week 1
Break a machine's job into steps
A watering robot is told to 'look after the seedlings'. What exactly should it do at 07:00 tomorrow?
Why should I care?
Computers are fast and obedient but have no common sense. Before an engineer writes a line of code, they split the job into pieces and write each piece as steps so precise that a machine cannot misread them. This habit, called computational thinking, is how every controller, from a greenhouse to a Mars rover, gets designed.
- Decompose an engineering job into smaller jobs that can each be solved and checked.
- Write an algorithm as ordered, numbered steps with quantities, units and a stopping rule.
- Spot a step that is too vague for a computer to follow and rewrite it precisely.
Predict
Which instruction could a watering controller actually follow?
- Water the plants when they look thirsty
- Water until the soil is wet enough
- Open the valve until soil moisture reaches 45 % or 60 s pass
Guess first, then reveal
Only the last one names something the controller can measure (moisture in %), a target (45 %) and a safety limit (60 s). 'Looks thirsty' and 'wet enough' mean something to a gardener but nothing to a computer.
Discover
Choose 'Seedling watering'. Use Up and Down to put the six steps in order, then mark the two steps a computer could not follow exactly. Check, then compare each vague step with its precise version.
What the interactive shows (text version)
The step orderer lists six shuffled steps for automatic watering: read moisture at 07:00; if moisture is 35 % or more skip to the last step; open the valve; keep it open until 45 % or 60 s; close the valve; log the time and moisture. Two steps start vague ('Check the plants in the morning', 'Water until the soil is wet enough'); the task is to order the steps and spot those two.
Watch (optional)
Watch for: Notice how each step of the counting method is exact enough for anyone to repeat, and how a cleverer algorithm does the same job in far fewer steps.
Counting a room full of people two at a time shows how a clever, exact procedure beats a slow one.
“What's an algorithm? - David J. Malan” by TED-Ed (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Decomposition: one big job, several small ones
'Look after the seedlings' is too big to solve in one go. Split it: sense (read moisture), decide (is it too dry?), act (open and close a valve), record (write a log line). Each piece is small enough to design, test and fix on its own, and different people can work on different pieces.
An algorithm is a precise recipe
An algorithm is a finite list of steps that solves one of those small jobs. Every step must be unambiguous: two people, or a computer, would do exactly the same thing. That usually means naming a quantity and a unit (35 % moisture, 60 s), and saying what happens next.
Every algorithm needs inputs, outputs and an end
Ask three questions of any algorithm. What does it read (inputs)? What does it produce (outputs)? How does it stop? A watering step without a stopping rule floods the tray. Good stopping rules often have a backup, such as 'or 60 s have passed', in case a sensor fails.
Explain it another way
Intuitive
Writing an algorithm is like writing directions for a friend who takes everything literally. 'Turn left at the shop' fails if there are two shops. 'Turn left at the second junction, by the red post box' works.
Technical
An algorithm is a finite sequence of well-defined instructions that maps inputs to outputs and terminates. Decomposition splits a problem into sub-problems with clear interfaces: what each piece receives and what it hands on.
Applied
Industrial irrigation controllers are written exactly this way: a schedule, a sensor threshold, a maximum valve-open time and a log. The maximum time is there because moisture sensors do fail, and a stuck-open valve can waste water or drown plants.
Worked example 1
Decompose 'keep the vaccine fridge between 2 °C and 8 °C' and write the decide step precisely.
Pieces: read the temperature every minute; decide; switch the compressor; log and alarm. Decide step: If the temperature is above 6 °C, switch the compressor on. If it is below 3 °C, switch it off. If it is outside 2–8 °C for 5 minutes in a row, sound the alarm. Each line names a number, a unit and an action.
Common mix-ups
An algorithm has to be written in a programming language.
✓ An algorithm is the method. It can be numbered steps, a flowchart or code; code is just one way to write it down.If a person understands the steps, a computer will too.
✓ People fill gaps with common sense. Computers need every quantity, unit and stopping rule spelled out.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Choose a simple machine at home or school (a kettle, an automatic door, a hand dryer). Decompose its job into sense, decide, act and record. Write the decide step as numbered, precise steps with at least one number and unit, and one backup limit.
Reflect
Which vague instruction from your own day would most confuse a computer, and how would you make it precise?
Write your answer on paper or in your own notes. Lite never stores what you write.