🔢 Number Guess (Up & Down)

Tries0
Best-

How to Play

The Math Behind It: Binary Search

Number Guess looks simple, but it is a hands-on way to learn a core computer-science algorithm: binary search. If you always call the exact middle of the remaining range, each guess cuts the candidates in half. For the range 1 to 100, going 50 to 75 to 63 and so on guarantees you find any number in at most 7 tries, because 2 to the 7th power is 128, which is greater than 100. By contrast, calling 1, 2, 3 in order could take up to 100 tries with bad luck. Real programs use this same principle to find a value in sorted data. If you beat the game in 7 tries or fewer today, you are already thinking as efficiently as a computer. It is also fun to bet with family or friends over who can do it in fewer tries.

Playing the Odds: What a Perfect Game Looks Like

Halving the range is the whole science, but the details reward precision. From 1–100 the perfect first call is 50; after "UP" the remaining range is 51–100, so the next call is 75, then 88 or 63, always the midpoint rounded either way. Every guess should shrink the candidate pool as close to exactly half as possible — a guess near the edge of the range is information wasted. It also pays to actually track the boundaries: keep the current low and high in your head (or on paper) and update one of them after every hint. Most losses to the 7-try par come not from bad strategy but from forgetting that an earlier hint already ruled out the number you are about to say. The history list under the input is there for exactly that reason — glance at it before each guess. And if you want a handicap match with a child, let them play the range 1–50: the same logic wins in at most 6 tries, so both of you can chase your own perfect game.

Where You'll Meet This Idea Again

Binary search is one of the most useful ideas in all of computer science, and once you have played this game you will recognize it everywhere. Looking up a word in a paper dictionary? You open near the middle and halve your way in — nobody flips page by page from "A". The parlor game Twenty Questions works because 20 yes/no answers can distinguish more than a million possibilities, which is the same doubling in reverse. Software engineers even debug with it: a tool in the Git version-control system called "bisect" finds the exact code change that broke a program by repeatedly testing the midpoint of history. And "guess the number" itself is a classic first project in nearly every beginner programming course, because it teaches loops, conditions and this exact algorithm in twenty lines of code. Not bad for a game you can explain in one sentence.

Try another game