Back to Puzzles
Puzzles › Number guess
Number guess
Find a hidden number from 1 to 100 in just 7 guesses. The trick: cut the range in half each time.
Number guess
I'm thinking of a number from 1 to 100. You have 7 guesses. (You only need ⌈log₂(100)⌉ = 7.)
Tries left: 7
Why 7?
Each guess can split the remaining range in half. Start with 100 possibilities. After one guess, at most 50. Then 25, 13, 7, 4, 2, 1. That's 7 guesses, worst case.
The strategy
- Guess the middle of the current range. First guess: 50.
- If "too low," the answer is between 51 and 100 — new midpoint 75.
- If "too high," answer is 1 to 49 — new midpoint 25.
- Keep halving.
Binary search
This trick is called binary search. It finds anything in a sorted list of N items in about log₂(N) steps. That's how computers look up dictionary words, find files, and build search engines.
The general formula
To guarantee finding a number from 1 to N, you need ⌈log₂(N)⌉ guesses. log₂(100) ≈ 6.64, so 7. log₂(1000) ≈ 9.97, so 10 guesses cover up to a thousand.