Pin the problem down· Make a spatial problem exact: what goes in, what comes out, what counts as done.
Last time you pinned the sprinkler job down: an oval that's L long and W wide, a spray that reaches r, and every point within r of a sprinkler. Now the plan has to be written so exactly that a machine could follow it. You found that one sprinkler covers a square a bit under 1.41 × r wide, so the plan uses 1.4 × r to stay on the safe side, and the oval is cut into cells that size or smaller with a sprinkler in the middle of each. The tricky part is deciding how many cells fit, so have a guess at that before the steps.
How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
Predict: Read the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Try: Try it on the board and compare the result with your prediction.
Investigate: Work out why it happens, one step at a time.
Modify: Change the problem on purpose and see what happens.
Practise: A few on your own, to check you have it.
Make: Make your own problem using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
How many cells?
You have a guess. Now here are the steps that give the answer.
TryTry it on the board and compare the result with your prediction.
The cell size
Steps 3 to 5 on the junior oval (L = 40, W = 24, r = 8): s = 1.4 × 8 = 11.2, then cols = 40 ÷ 11.2 rounded up. After that, w = 40 ÷ cols. How wide is one cell, in metres?
InvestigateWork out why it happens, one step at a time.
Steps, decisions and loops
The sprinkler algorithm
Say which steps compute, which decide, and which repeat. Here are the steps in full.
Read the oval's length L, its width W and the spray's reach r, all in metres.
If L, W or r is zero or less, say "not an oval" and stop.
Set s = 1.4 × r.
Set cols = L ÷ s, rounded up, and rows = W ÷ s, rounded up.
Set w = L ÷ cols and h = W ÷ rows.
For each row j from 1 to rows, and each column i from 1 to cols, put a sprinkler at x = (i − 0.5) × w and y = (j − 0.5) × h.
Say how many sprinklers there are (cols × rows), and where each one is.
Here is the whole algorithm run on the junior oval.
Worked exampleBefore each step, say what you think comes next.
s=1.4×8=11.2Step 3.
cols=40÷11.2≈3.57→4Step 4: round up, since a part-cell still needs a sprinkler.
rows=24÷11.2≈2.14→3Step 4 again.
w=40÷4=10,h=24÷3=8Step 5. The cells come out a little smaller than the biggest square, so they stay covered.
x=5,15,25,35;y=4,12,20Step 6: the middle of each cell is (i−0.5)×w across and (j−0.5)×h down.
4×3=12Step 7.
Now run it yourself on paper, on the senior oval, with the example beside you. Write each step's result, then pick the reason for rounding up.
Check where Zoe's first sprinkler lands, and where its cell's middle is.
Build up to it
On the junior oval each cell is 10 m wide. How far along the 40 m side is the middle of the first cell, in metres?
Think about what you'd have to write without a loop.
Here is the algorithm, step by step. What does each step do?
Step 2: If L, W or r is zero or less, say 'not an oval' and stop
Step 3: Set s = 1.4 × r
Step 4: Set cols = L ÷ s and rows = W ÷ s, each rounded up
Step 5: Set w = L ÷ cols and h = W ÷ rows
Step 6: For each row and each column, put a sprinkler in the middle of the cellIt repeats the same placing for every cell.
Step 7: Say how many sprinklers, and where each one is
Run the algorithm by hand on the senior oval: L = 60 m, W = 30 m, r = 8 m (made up). Write each step's result, then how many sprinklers it places.
Work it out on paper first, one step per line. Then type your answer.
Put your page beside this and compare, step by step.
A model solution
s=1.4×8=11.2step 3
cols=60÷11.2≈5.36, rounded up to 6step 4: a part-cell still needs a sprinkler
rows=30÷11.2≈2.68, rounded up to 3step 4
w=60÷6=10 and h=30÷3=10step 5
6×3=18 sprinklers step 7: one in each cell
Check your page
Zoe tries her algorithm on the junior oval (w = 10, h = 8) and finds the left end of the oval is out of reach of every sprinkler. Click the line where it goes wrong.
ModifyChange the problem on purpose and see what happens.
Change the oval
Run it on an oval exactly 11.2 m long and 11.2 m wide (r = 8). How many sprinklers does it place?
Run it on an oval 11.5 m long and 4 m wide (r = 8). How many sprinklers does it place?
PractiseA few on your own, to check you have it.
Run it
Run the algorithm on an oval 50 m long and 20 m wide (r = 8, so s = 11.2). How many sprinklers does it place?
On that oval each cell is 10 m wide. How far along the 50 m side is the middle of the first cell, in metres?
Review: a cell is 6 m wide and 8 m tall, with the sprinkler in the middle. How far is the sprinkler from a corner, in metres?
MakeMake your own problem using what you have learned. Expect a few tries; that is normal.
The other oval
Write this on paper first, a step at a time.
Also used in
Packing a van. A loop places one box after another, a decision rejects a box that's too big, and the steps are exact enough for a program.
Laying paving or tiles. The same rounding up and the same cell by cell placing.
Testing and refining. The next job is to test an algorithm on awkward ovals, such as a curved one or one with a tree in the way, find where it fails, and improve it. That's for your class project.
The caretaker's third oval is 36 m long and 20 m wide, with an 8 m spray (made up). Run the algorithm by hand. Write each step's result, then how many sprinklers it places.
Work it out on paper first, one step per line. Then type your answer.
Put your page beside this and compare, step by step.
A model solution
s=1.4×8=11.2step 3
cols=36÷11.2≈3.21, rounded up to 4step 4
rows=20÷11.2≈1.79, rounded up to 2step 4
w=36÷4=9 and h=20÷2=10step 5
4×2=8 sprinklers step 7
Check your page
Now test the answer. Each cell on that oval is 9 m by 10 m with its sprinkler in the middle. How far is the sprinkler from a corner of its cell, to 1 decimal place? Is it within 8 m?
Lesson done. You've finished every step you need.
Now you can
Write the steps of an algorithm exactly enough for a machine.
Say which steps compute, which decide and which repeat.
Students turn the pinned-down sprinkler job into numbered steps with a decision and a loop, run the steps by hand on two ovals, and find a bug where a sprinkler is placed on the edge of its cell instead of the middle (AC9M10SP03, node 2). About 45 minutes.
I can write the steps of an algorithm exactly enough for a machine.
I can say which steps compute, which decide and which repeat.
I can run an algorithm by hand on two different inputs.
Before class
Do the Predict and the senior oval yourself first. Students need Pin the problem down, Pythagoras and the Year 9 idea that an algorithm has computation and decision steps.
The one idea: an algorithm is exact steps that work for any input. Here the steps cut the oval into cells no wider than 1.4 × the reach (the biggest square is about 1.41 × the reach, so 1.4 is on the safe side), with a sprinkler in the middle of each cell. A decision guards the input and a loop places one sprinkler in every cell.
The steps always cover the oval, but they don't always use the fewest sprinklers: the 11.5 m by 4 m oval in Modify needs two when one would do. That is on purpose, to show the gap. Testing awkward ovals (a curved one, a tree in the middle), finding where the algorithm fails and refining it is node 3, the class project, and isn't covered here.
The junior and senior ovals, the reach and the sizes are all made up. A flowchart or pseudocode both work; the numbered steps and the flowchart in the lesson say the same thing.
Running the lesson
Predict: take a show of hands. Most will say 6 or 9. Ask a student to say what happens to the leftover strip.
Paper: the senior oval and the third oval are worked on paper first, a step at a time, with the steps beside you.
Investigate: ask a student to point at the loop and say what would have to be written without it.
Modify: before 11.5 m by 4 m, ask whether the algorithm will place one or two.
Make: ask whether the answer meets the success criterion, and how they know.
The hard part (on purpose)
Rounding a count down, and putting a sprinkler on the edge of its cell. Ask: what is left over if you round down? Where is the middle of the first cell?
When students get stuck
A student rounds 3.57 to 4 for one side and 2.14 to 2 for the other. Ask: What happens to the last strip on the short side? Fix: Round both counts up: any part-cell still needs a sprinkler.
A student sets the cell size to s, not to L ÷ cols. Ask: Do the cells fill the oval exactly? Fix: Divide each side by the rounded count, so the cells fit with no gaps.
A student puts the sprinkler at x = i × w. Ask: Where is the middle of the first cell? Fix: Half a cell in: (i − 0.5) × w.
Stretch and support
Stretch: Write the same algorithm in pseudocode with a loop that reads a list of ovals and prints each count, then try a staggered layout, where every second row is shifted half a cell, and see whether it needs fewer sprinklers.
Support: A printed copy of the seven steps and a blank table with columns for s, cols, rows, w, h and the count.
Where it leads
This covers AC9M10SP03 node 2.
Node 3 (testing, refining and justifying) is left to class: the project is to test this algorithm on the school's own oval, find where it fails, and refine it. Where it leads: the same habit of pinning down, then writing steps, then testing, for any spatial job.
What each step is for
how many cells?: Committing to a number of sprinklers shows who rounds a count down or to the nearest whole number. The algorithm's key detail is that a part-cell still needs a sprinkler, and the oval has two different sides to count.
the cell size: Following the first steps of the algorithm on a real oval shows that after rounding up the cells come out a little smaller than the biggest square, and that is why they stay covered.
steps, decisions and loops: An algorithm for a spatial problem has computation steps, a decision that guards the input, and a loop that repeats one placement for every cell. Zoe's mistake is a wrong formula in the loop: the sprinkler goes on the cell's edge, not its middle.
change the oval: Running the algorithm on an oval with an exact fit, on one that is just over, and with a different spray, to see what changes and what the algorithm does when the answer isn't the fewest.
run it: Running the algorithm on new ovals, finding a sprinkler's position, spotting a boundary case, and a review of a cell's half-diagonal.
the other oval: Returning to the sprinkler job: running the whole algorithm on a new oval, then checking the answer against the success criterion.