How to Play the Number Guessing Game
The computer picks a secret number within the chosen range. You enter guesses one at a time, and the game responds with Too High or Too Low after each attempt. Your goal is to find the exact number in as few guesses as possible.
Binary Search Strategy
The most efficient strategy is binary search: always guess the midpoint of the current possible range. If the range is 1–100, guess 50. If told too high, the range becomes 1–49 — guess 25. This approach guarantees finding any number in 1–100 within 7 guesses, any number in 1–1000 within 10 guesses.
Why Is This Game Educational?
The guessing game is a classic introduction to binary search — one of the most fundamental algorithms in computer science. It demonstrates how logarithmic efficiency works in practice: doubling the range only adds one extra guess needed.
Comments