Number Guessing Game

The computer picks a secret number. Guess it with higher/lower hints. Three difficulty levels with best score tracking per difficulty.

Best Scores

easy
1-100
--
medium
1-1,000
--
hard
1-10,000
--

Number Guessing Game — Binary Search in Action

The number guessing game is a classic exercise in binary search strategy. By always guessing the midpoint of the remaining range, you can find any number in 1-100 in at most 7 guesses, 1-1,000 in 10, and 1-10,000 in 14.

Three difficulty levels challenge you to apply this strategy under increasing ranges. Best scores are tracked per difficulty so you can compete against your own record. All data is stored locally in your browser.

How the Number Guessing Game Works

  1. Choose a difficulty level: Easy (1-100), Medium (1-1000), or Hard (1-10000)
  2. Enter your guess and submit — the game tells you if the secret number is higher or lower
  3. Use the feedback to narrow your range and guess again
  4. Find the number in as few guesses as possible — optimal play uses binary search

Binary Search Strategy

The optimal strategy is to always guess the midpoint of the remaining range. Start at 50 for 1-100, then go to 25 or 75 based on the hint. This binary search approach guarantees finding any number in at most 7 guesses (1-100), 10 guesses (1-1000), or 14 guesses (1-10000). Each guess eliminates exactly half of the remaining possibilities.

When to Play

A perfect quick mental exercise during breaks, an excellent way to teach children about estimation and number sense, or a fun way to demonstrate the binary search algorithm to programming students. The game takes 30 seconds to 2 minutes depending on difficulty.

Common Use Cases

  • Teaching binary search and algorithmic thinking
  • Quick mental exercise and number sense training
  • Kids' math practice with estimation and number ranges
  • Programming concept demonstration for CS students

Expert Tips

  • Always guess the exact midpoint of the remaining range — this is mathematically optimal.
  • Keep track of your range boundaries mentally: if the answer is higher than 50 and lower than 75, guess 62 or 63.
  • Challenge yourself to match the theoretical minimum: 7 guesses for Easy, 10 for Medium, 14 for Hard.

Frequently Asked Questions

What is the minimum number of guesses needed?
With optimal play: 7 for Easy (1-100), 10 for Medium (1-1000), and 14 for Hard (1-10000). This follows the formula: ceil(log2(n)).
Are best scores saved?
Yes, your best score per difficulty level is saved in localStorage and displayed as a personal record to beat.
Is the secret number truly random?
Yes, the number is selected using cryptographically secure randomness from the Web Crypto API.
Can I play multiple rounds?
Yes, after each game you can start a new round with the same or different difficulty level.

Related Tools