← CS Unplugged

CS Unplugged activity

Clocks That Wrap Around: the modulo idea

About 20 minutesSoloPencil

Some numbers wrap around instead of growing forever, like the hands on a clock. This wraparound trick is called modulo, and computers use it all the time. You’ll count around a few clocks, then predict a computer’s own version of it.

Learn more: clocks are one example of modular arithmetic, a whole branch of math built on wraparound counting.

  1. Look at the clock below. It has 10 spots, numbered 0 to 9.
  2. Start at the number you’re given.
  3. Count forward that many steps around the circle, going past 9 back to 0.
  4. Write down the spot where you land.
  5. Check yourself: it’s always the last digit of start + steps added normally.
0123456789
A 10-clock: positions 0 through 9

For example: start at 7, count forward 4 steps: 8, 9, 0, 1. You land on 1. Quick check: 7 + 4 = 11, and 1 is the last digit of 11. That will always work on this clock, because it only has 10 spots.

Count forward

Start atCount forwardLand on
23 steps
65 steps
347 steps

Counting backward

Counting backward works the same way, just going the other direction. Past 0, you wrap around to 9 instead.

For example: start at 2, count backward 5 steps: 1, 0, 9, 8, 7. You land on 7.

Start atCount backwardLand on
35 steps
513 steps

Other clocks

The same wraparound idea works for any size clock, not just 10. Here are five you already use in real life.

121234567891011
12-hour clock
It is 9 o'clock. What time is it 6 hours later?
SunMonTueWedThuFriSat
Days of the week
Today is Thursday (day 4). What day is it 10 days from now?
EvenOdd
Even and odd
Is 17 even or odd?
24-hour & 360° A 24-hour clock wraps from 23 back to 0; a full turn (360°) works the same way. A movie starts at 22:00 and runs for 3 hours. What time does it end? You spin a dial 370 degrees, starting at 0. Where does it point, as a number from 0 to 359?

Predicting a computer’s version

Python, a programming language, writes this exact same idea as %. 17 % 5 means “count forward 17 steps on a 5-spot clock (0, 1, 2, 3, 4), starting at 0. Where do you land?” Try it: 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2. That’s 17 steps, landing on 2. So 17 % 5 is 2.

ExpressionPredict the value
20 % 7
5 % 8
7 % 2

Count forward. 2+3→5. 6+5→1. 3+47→0.

Counting backward. 3−5→8. 5−13→2.

Other clocks. 12-hour clock: 3 o’clock. 24-hour clock: 01:00. Days of the week: Sunday. Degrees in a circle: 10 degrees. Even and odd: Odd (position 1).

Predicting %. 20 % 7 = 6. 5 % 8 = 5. 7 % 2 = 1.

Adapted from CS Unplugged, by Tim Bell and the CS Unplugged team, University of Canterbury (csunplugged.org). Licensed under CC BY-SA 4.0.