Number Guessing Game
Classic guess-the-number game with hints, optimal binary search analysis, and a reverse mode where the computer guesses your number.
Sobre esta ferramenta
Play the classic number guessing game with a twist — after you solve it, the game shows the binary search strategy that would have found the number in the minimum possible guesses. Choose Easy (1–50), Medium (1–100), or Hard (1–1000) difficulty, or set a fully custom range. The computer picks a secret random number; you guess and receive 'too high' or 'too low' feedback until you find it. A visual history list tracks every guess and narrows the displayed range in real time. The info panel always shows how many guesses you've used and the theoretical minimum (⌈log₂ n⌉). After solving, an animated walkthrough demonstrates the optimal binary search path step by step. In Reverse Mode, you think of a number and the computer guesses it using binary search — you only reply Higher, Lower, or Correct. Perfect for understanding algorithmic thinking and search complexity.
Como usar
- 1 Choose a difficulty (Easy, Medium, Hard) or set a custom min/max range.
- 2 Type your guess in the input field and press Enter or click Guess.
- 3 Read the 'Too High' or 'Too Low' hint and use the narrowing range display to plan your next guess.
- 4 Continue guessing until you find the number — your guess count is tracked throughout.
- 5 After solving, click 'Show Optimal Strategy' to see the binary search walkthrough.
- 6 Try Reverse Mode: think of a number and let the computer find it using binary search.
A guessing game that teaches an algorithm
On the surface this is the classic parlour game: the computer picks a secret number in a range, you guess, and it tells you "too high" or "too low" until you find it. What makes this version worth your time is that it scores your performance against the mathematically optimal strategy — binary search — and then shows you, step by step, the exact path that strategy would have taken. Play a few rounds with that feedback in front of you and you internalise one of the most important ideas in computer science by feel rather than by memorisation.
Why halving is optimal
Each "too high / too low" answer carries one bit of information: it eliminates everything above or below your guess. The way to extract the most from every guess is to make each answer cut the remaining possibilities exactly in half — and the only guess that does that is the midpoint of the range you have left. Guess too near an edge and a single answer might rule out only a sliver; guess the middle and you are guaranteed to discard half no matter what the answer is. That guarantee is what makes binary search the best possible strategy for the worst case.
The formula, and why it's a ceiling
If a range holds n numbers, the minimum number of guesses you can be forced to make is ⌈log₂(n)⌉ — the base-2 logarithm rounded up. The intuition: each guess at most doubles the size of range you can handle, so to cover n values you need enough guesses that 2 raised to that count reaches n. The rounding-up matters because you cannot make a fractional guess. The info panel shows this number live for whatever range you choose:
| Difficulty | Range | Values (n) | Optimal guesses ⌈log₂ n⌉ |
|---|---|---|---|
| Easy | 1–50 | 50 | 6 |
| Medium | 1–100 | 100 | 7 |
| Hard | 1–1000 | 1000 | 10 |
Notice the payoff of logarithmic growth: the Hard range is twenty times larger than Easy, yet needs only four more guesses. Doubling the range adds just one guess. That is why binary search scales to enormous datasets while a linear scan does not.
A worked example: finding 73 in 1–100
The optimal path the walkthrough draws looks like this. Guess the midpoint, 50 — too low, so the range becomes 51–100. Midpoint 75 — too high, range 51–74. Midpoint 62 — too low, range 63–74. Midpoint 68 — too low, range 69–74. Midpoint 71 — too low, range 72–74. Midpoint 73 — correct. Six guesses, comfortably inside the 7-guess ceiling. The tool builds exactly this list after you win and labels each step with the range that remained, so you can compare your own guesses against the ideal and see precisely where you wasted a turn.
Reverse Mode: the computer guesses your number
Flip to Reverse Mode and you think of a number while the computer applies binary search, asking you to answer Higher, Lower, or Correct. It always offers the midpoint of its current bounds, so on a 1–100 range it will pin any number you chose in at most seven questions — try to "beat" it and you can't, because the strategy is provably optimal. This mode is the most convincing demonstration that an algorithm with zero prior knowledge of your number still solves the problem in the minimum number of steps. Answer honestly: contradictory replies will drive the lower bound above the upper bound and the search collapses, which is itself a useful lesson about why the answers must be consistent.
Practical tips
- Always open with the midpoint. On 1–100 your first guess should be 50, not a lucky number. The input field even pre-fills the current midpoint as a hint — following it is how you stay on the optimal line.
- Read the remaining-range display, not your gut. After each hint the tool narrows the shown bounds; aim your next guess at the centre of that live range, not the original one.
- Use a custom range to test the formula. Set 1–8 and you'll find any number in exactly 3 guesses, because log₂(8) is a clean 3 — a tidy way to confirm the maths.
Common mistakes
- Guessing sequentially. Starting at 1 and counting up (linear search) needs up to n guesses — 100 on the Medium range versus 7 for binary search. It feels safe but it is the slowest possible method.
- Forgetting the range shrinks both ways. A "too high" lowers the ceiling and a "too low" raises the floor. Re-centre on the new bounds each turn; chasing your previous guess instead of the new midpoint costs extra turns.
- Confusing average with worst case. The ⌈log₂ n⌉ figure is the worst case. You'll sometimes get lucky and land the answer sooner, but you can never be forced to exceed it — that ceiling is the guarantee, not the typical result.
Perguntas frequentes
Role dados poliédricos de RPG usando notação padrão como 2d6+1d8+5.
Role dados, jogue moedas, sorteie cartas aleatórias e gere números aleatórios — todos criptograficamente aleatórios.
Classic card-flip memory matching game with emoji themes, multiple grid sizes, and best-score tracking.
Visualize a sequência de Fibonacci, a espiral áurea animada e a convergência da razão em direção a φ.