2how it works
In the puzzle, the outer loop runs over the rows, from 1 to 8, and on row the inner loop plants bulbs. The inner loop grows by 1 each pass.
An 8 by 8 square holds 64. The squares on or below the diagonal, 1 to 8 by row, are the bulbs, 36. The 28 above them are the rest of the square. So the bulbs are . Lesson 5.2's total gives .
If every row got 8 bulbs, the rows would be the same length and make a square, . The growing loop plants a little over half of that.
3in symbols
Lesson 7.1 summed loops placed end to end. Here each outer pass repeats the whole inner loop: outer passes, each running inner steps, take steps.
A third loop inside multiplies again. With passes each, three loops take , and with 2 passes each, .
An inner counter halving from runs times (lesson 7.1), so outer passes take steps. For , the counter runs at 16, 8, 4 and 2, 4 passes, so .
If pass 's inner loop runs times, the total is , which is .
If pass 's inner loop runs times, the total is . That is terms from 0 to , so lesson 5.2's first form gives . For , .
This happens when each new item is checked against every one before it.
So one total is and the other : half the square, give or take .
For , that is and : the matters less as grows.
The square less the growing staircase is the other staircase, just under half. 4your turn
Work each one out. Where there is a box, type your answer and check it. Each exercise's worked answer opens under it.
1exercise 1
An outer loop runs over 14 days. Each day, an inner loop checks 9 sensors, at 3 steps a sensor.
worked answer
- One day's inner loop takes steps.
- The outer loop runs it 14 times, so steps.
Check it another way: Counted the other way, checks, at 3 steps each, is .
2exercise 2
An outer loop makes 56 passes. On each, an inner counter starts at 56 and is halved, rounding down, while it is above 1. Each inner pass takes 1 step.
worked answer
- The inner counter runs at 56, 28, 14, 7 and 3, and at 1 it stops.
- That is 5 passes. As , too (lesson 6.4).
- The outer loop runs it 56 times, so steps.
Check it another way: outer passes of a halving inner loop take steps, and .
3exercise 3
Three loops sit one inside another, and each runs 6 times. The innermost does 2 steps a pass.
worked answer
- The innermost loop runs times in all.
- At 2 steps a pass, steps.
Check it another way: One middle pass takes steps, one outer pass , and 6 outer passes .
4exercise 4
A loop takes photos, one at a time. Each new photo is compared with every photo taken before it, at 1 step a comparison. For photos, the steps are .
worked answer
- Photo is compared with the photos before it, so the steps are .
- That is terms from 0 to , so lesson 5.2's first form gives .
- For 15 photos, .
Check it another way: For 3 photos, the comparisons are 0, 1 and 2, which is 3, and .
5exercise 5
An outer loop runs from 1 to 26, and on pass its inner loop runs times, at 1 step each. A square loop, 26 inner steps every pass, would take .
worked answer
- The steps are .
- That is .
Check it another way: , a little over half of 676.