🔢 Number Guess (Up & Down)
How to Play
- The computer secretly picks a number between 1 and 100.
- Enter a number and it tells you "UP" if the answer is higher, or "DOWN" if it is lower.
- Use the hints to narrow the range and find the answer.
- Your number of tries is counted, and your fewest-tries record is saved.
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.