Skip to content

the totals on step counts

foundations

the puzzle

A loop's pass kk does 5k+25k + 2 steps, for kk from 1 to nn. How many steps does the whole loop do, as a formula in nn?

a worked example

Three lists, and which total each one takes.

  1. For 11, 19, 27, 35, take each number from the next. The gaps are 8, 8 and 8, so it has a fixed gap.
  2. For 2, 14, 98, 686, divide each number by the one before. The ratios are 7, 7 and 7, so it is made by multiplying.
  3. For 2, 5, 11, 23 the gaps are 3, 6 and 12, and the ratios 5÷2=2.55 \div 2 = 2.5 and 11÷5=2.211 \div 5 = 2.2 already differ. This course has no total for it yet.
  4. Take the first list on up to 83. It has a fixed gap, so lesson 5.2's first form gives its total once its count is found, as the table under how it works shows.
listgapsratioskindtotal
11, 19, 27, 358, 8, 8differfixed gapn(a1+an)2\frac{n(a_1 + a_n)}{2}
2, 14, 98, 68612, 84, 5887, 7, 7made by multiplyinga1(rn−1)r−1\frac{a_1(r^n - 1)}{r - 1}
2, 5, 11, 233, 6, 122.5, 2.2: differneithernone yet
One gap all along, or one ratio all along, decides which total to use.

how it works

The table takes the first list through, row by row: its gaps pick the total, its last term gives nn as in lesson 4.2, and the numbers go in.

stage11, 19, 27 and on, up to 83
kindgaps 8, 8, so a fixed gap
count83−11=7283 - 11 = 72, and 72÷8=972 \div 8 = 9 gaps, so 10 terms
total10×(11+83)2=470\frac{10 \times (11 + 83)}{2} = 470
checkn=1n = 1, the last term is 11 too, so 1×(11+11)2=11\frac{1 \times (11 + 11)}{2} = 11
checksecond form, 10×(2×11+9×8)2=470\frac{10 \times (2 \times 11 + 9 \times 8)}{2} = 470
Kind, count, total and check on the first list.

Then test it twice. A total of one term is that term, so n=1n = 1 must give a1a_1, and the other form must give the same total.

in symbols

A loop's step count, its steps added over every pass, is often a sum. In the puzzle, pass kk does 5k+25k + 2 steps, so the loop does ∑k=1n(5k+2)\sum_{k=1}^{n} (5k + 2).

Each pass raises kk by 1, so 5k+25k + 2 grows by 5. Passes 1, 2 and 3 do 7, 12 and 17, a fixed gap of 5, and a1=7a_1 = 7.

kk runs from 1 to nn, so there are nn terms, and the last pass, k=nk = n, does an=5n+2a_n = 5n + 2.

The first form gives n(7+5n+2)2\frac{n(7 + 5n + 2)}{2}, which gathers to n(5n+9)2\frac{n(5n + 9)}{2}.

Check it. At n=1n = 1 it gives 1×142=7\frac{1 \times 14}{2} = 7, the first pass. At n=5n = 5 it gives 5×342=85\frac{5 \times 34}{2} = 85, and 7+12+17+22+27=857 + 12 + 17 + 22 + 27 = 85.

nnsteps of each passaddedn(5n+9)2\frac{n(5n + 9)}{2}
1777
27, 121919
37, 12, 173636
47, 12, 17, 225858
The closed form agrees with the passes added by hand.

your turn

Work each one out. Where there is a box, type your answer and check it. Each exercise's worked answer opens under it.

exercise 1

Each of a loop's nn passes does 9 steps, whatever the pass.

A number, like 13, 9.5 or 19/2.

worked answer
  1. Pass 1, pass 2, and on to pass 40, each does 9, and lesson 4.4 gives ∑k=1n9=9n\sum_{k=1}^{n} 9 = 9n.
  2. At n=40n = 40 that is 9×40=3609 \times 40 = 360.

Check it another way: At n=1n = 1, 9×1=99 \times 1 = 9, the one pass.

exercise 2

A loop's pass 1 does 6 steps, and each pass does 5 times as many as the one before. It runs 4 passes.

A number, like 13, 9.5 or 19/2.

worked answer
  1. The passes do 6, 30, 150 and 750 steps. The ratios are 5, 5 and 5, so it is made by multiplying, with a1=6a_1 = 6, r=5r = 5 and n=4n = 4.
  2. The total is 6×(54−1)5−1=6×6244\frac{6 \times (5^4 - 1)}{5 - 1} = \frac{6 \times 624}{4}.
  3. That is 37444=936\frac{3744}{4} = 936 steps.

Check it another way: Added by hand, 6+30+150+750=9366 + 30 + 150 + 750 = 936.

exercise 3

A loop's counter kk runs from 1 to 20, one pass for each: pass 1 does 6 steps, and each pass does 5 more than the one before.

A number, like 13, 9.5 or 19/2.

worked answer
  1. The gaps are all 5, so it has a fixed gap, with a1=6a_1 = 6, d=5d = 5 and n=20n = 20. The last pass is not given, so the second form fits.
  2. The second form is n(2a1+(n−1)d)2\frac{n(2a_1 + (n - 1)d)}{2}. Here 2a1=122a_1 = 12 and (n−1)d=19×5=95(n - 1)d = 19 \times 5 = 95, so the bracket is 12+95=10712 + 95 = 107.
  3. The second form gives 20×1072=10×107=1070\frac{20 \times 107}{2} = 10 \times 107 = 1070.

Check it another way: The last pass does 6+19×5=1016 + 19 \times 5 = 101 steps, and the first form gives 20×(6+101)2=1070\frac{20 \times (6 + 101)}{2} = 1070 too.

exercise 4

A loop's pass kk does 6k+16k + 1 steps, for kk from 1 to nn.

The whole loop does:

A number, like 13, 9.5 or 19/2.

worked answer
  1. Each pass raises kk by 1, so 6k+16k + 1 grows by 6. Passes 1, 2 and 3 do 7, 13 and 19, so a1=7a_1 = 7, and the last pass, k=nk = n, does an=6n+1a_n = 6n + 1.
  2. The first form gives n(7+6n+1)2\frac{n(7 + 6n + 1)}{2}, which gathers to n(6n+8)2\frac{n(6n + 8)}{2}.
  3. Take out 2, as in lesson 2.3, so 6n+8=2(3n+4)6n + 8 = 2(3n + 4), and the top is n×2(3n+4)n \times 2(3n + 4).
  4. The 2 on top cancels the 2 below, leaving n(3n+4)n(3n + 4).
  5. Without the halving, n(6n+8)n(6n + 8) gives 1×14=141 \times 14 = 14 at n=1n = 1, twice the first pass, so it fails the check.

Check it another way: At n=1n = 1, n(3n+4)n(3n + 4) gives 1×7=71 \times 7 = 7, the first pass. Passes 1 and 2 do 7+13=207 + 13 = 20, and at n=2n = 2 it gives 2×10=202 \times 10 = 20.