"I am thinking of a number between one and a hundred." Everyone has played it. In Secret Number one player chooses, the other guesses, the game says "too high" or "too low", and then you swap. Fewer guesses wins.
There is a best way to guess. It never needs more than seven tries. And once you know it, the interesting question becomes how to choose a number that makes it work as hard as possible.
The method
Always guess the middle of what is left.
Start at 50. Suppose the answer is "too high". The number is somewhere from 1 to 49. Guess the middle: 25. "Too low." Now it is between 26 and 49. Guess 37.
Each guess cuts the remaining numbers roughly in half.
- At the start there are 100 possibilities.
- After one guess, at most 50.
- After two, at most 25.
- After three, 12.
- After four, 6.
- After five, 3.
- After six, 1.
So the seventh guess, at the latest, must be right.
Why halving is the best you can do
Each answer you get is one of two things: higher or lower. That is a single yes-or-no piece of information. The most a yes-or-no answer can do is split the possibilities into two groups and tell you which one you are in.
If the groups are equal, you are guaranteed to lose half of them whichever answer comes back. If they are unequal, you might get lucky and land in the small group. But more often you will land in the big one, and you have wasted part of a guess.
Guessing 10 first is an example. One time in ten, the number is below 10 and you have done very well. Nine times in ten, it is above, and you have removed only ten numbers.
Seven guesses is enough because two multiplied by itself seven times is 128, which is more than 100. Six would not be, because that gives only 64.
The same idea runs the modern world
Programmers call this binary search. It is how a computer finds a name in a sorted list of millions without reading them all. Twenty halvings are enough to search a million items. Thirty are enough for a billion.
You do it yourself when you look up a word in a paper dictionary. You do not start at page one. You open near the middle, see whether you have gone too far, and jump again.
This is why we think Secret Number is a good game to play with a child. The moment they stop creeping up in tens and start halving, they have learned something they will use for the rest of their life.
Now, the choosing
If both players halve perfectly, the match is decided by which numbers were chosen. Some are found quickly and some slowly.
Follow the method and see when each number turns up.
- Guess 1: 50.
- Guess 2: 25 or 75.
- Guess 3: 12, 37, 62 or 88.
Anyone who picks 50, 25 or 75 against a halving opponent has thrown the round away.
At the other end, about a third of all the numbers take the full seven guesses. Exactly which ones depends on how your opponent rounds when the middle falls between two numbers, so there is no single perfect choice. As a guide, stay away from the obvious midpoints and the numbers next to them, and pick something that looks unremarkable.
Guessing the guesser
That advice assumes your opponent halves. Many do not.
The creeper goes 10, 20, 30, and so on, then counts up in ones. Against them, a high number ending in nine is cruel. 99 takes close to twenty guesses.
The lucky-number player begins with a favourite and wanders. Anything far from 7 or 50 will do.
The halver is the only one you cannot do much about. All you can do is avoid the early midpoints.
Watch how they guess in the first round. You will be setting the number in the second, or the other way round, and you will know which kind of player you are facing.
When you both know the method
Then luck decides most rounds, and they will be close: six guesses against seven, or seven against seven and a draw.
To make it a contest again, change the game. A few ideas:
- Bigger range. Agree to imagine 1 to 1,000. It takes ten guesses, and the halving sums get harder to do in your head.
- Mental only. No writing down the range. You have to remember your own limits.
- Bluffing version, without the screen. Play aloud and let the chooser lie once. That changes everything, and it is a famous puzzle in its own right.
A note on fair play
In our game the secret number is typed on a keypad and shown as dots, and a handover screen appears before the device changes hands. It still relies on the second player looking away while the first one types. Agree that before you start.
Two minutes well spent
Among the HTML5 games on TwoSide, this is probably the shortest that teaches something lasting. Play it once by instinct. Then play it by halving. The difference is the lesson.