Skip to content

Hour of Code · Unplugged activity

How Does a Computer Think?

20 min

Add up every number from 1 to 12 without adding them one by one, and learn the four thinking steps behind every program.

What it teaches

Computational thinking, the way a programmer breaks a problem apart before touching a keyboard. It has four moves: decomposition (split a big problem into smaller ones), pattern-finding (spot what repeats), abstraction (drop the details that do not matter and keep the rule), and algorithm (write the exact steps that solve it). A computer is fast but not clever; this thinking is the part that is yours.

What you'll need

  • A whiteboard or paper with the numbers 1 to 12 written in a row.
  • Something to draw arcs linking pairs of numbers; a coloured pen helps.
  • No calculators. The whole point is to avoid adding by brute force.

How to run it

  1. 1

    Decomposition. Start with the whole task, add 1+2+3 and so on up to 12. Adding twelve numbers one after another is slow and easy to get wrong, so break it into a smaller job you can repeat.

  2. 2

    Pattern-finding. Pair the smallest number with the largest: 1+12. Then 2+11, then 3+10. Every pair adds up to the same thing, 13. That repetition is the pattern.

  3. 3

    Abstraction. Now drop the specific numbers and keep only the rule: there are six such pairs, and each one is worth 13. The individual numbers no longer matter.

  4. 4

    Algorithm. Turn the rule into steps: count the pairs (6), multiply by the pair total (13), and you get 6 × 13 = 78. Check it any other way you like; it holds.

  5. 5

    Generalise. Ask what happens for 1 to 100, or 1 to any number n. The same idea gives a formula: pair total times number of pairs, which is n × (n + 1) ÷ 2. You have just derived what a program would use.

Try it now

Practise on three sums. 1 to 10: five pairs of 11, so 5 × 11 = 55. 4 to 15: that is twelve numbers, six pairs of 19 (4+15), so 6 × 19 = 114. 1 to 99: ninety-nine numbers do not pair evenly, so take 99 × 100 ÷ 2 = 4950, or make 49 pairs of 100 and add the lonely middle number, 50. The pattern bends to fit; that is abstraction working.

Talk about it

Ask: which of the four steps was the hard one? Almost always it is spotting the pattern. Once you see it, the algorithm writes itself, and that is the work a computer cannot do for you.

Developed by alphaPlan Center.

Found something unclear, outdated or improvable? Suggest an improvement