TPToolpazar

Global Araç

Number Guess

1'den 100'e bir sayı tutuyorum

Tahminler: 0

En iyi ikili arama stratejisi 1-100 arası herhangi bir sayıyı en fazla 7 tahminde bulur. Rastgele tahmin ortalaması ~50'dir.

Classic 1-100 number guessing game. The computer picks a random number between 1 and 100, you guess, and after each guess you get a "higher" or "lower" hint until you land on it. Your best score (lowest number of guesses) is saved across sessions in your browser.

Beyond being a quick brain warm-up, the game is the canonical introduction to binary search — one of the most important algorithms in computer science. The optimal strategy is to always guess the middle of the remaining range, halving the search space with each turn. Starting range is 1-100, so:

  • Guess 1: 50 (range becomes 1-49 or 51-100, ~50 numbers)
  • Guess 2: middle of new range (~25 numbers left)
  • Guess 3: ~12 left
  • Guess 4: ~6
  • Guess 5: ~3
  • Guess 6: ~1-2
  • Guess 7: definitely the answer

Worst case 7 guesses for any 1-100 target. Average for random play: 5-6. The math: log₂(100) ≈ 6.64, rounded up to 7. This is exactly how you'd binary-search a sorted array of 100 elements — same algorithm, same complexity, same lower bound.

Nasıl Kullanılır

  1. Type a number between 1 and 100 in the input.
  2. Press Guess or Enter to submit.
  3. The game tells you 'higher' or 'lower' (or 'correct!').
  4. Keep guessing until you find the answer. Your guess count is shown.
  5. After winning, click 'Play again' for a new random target. Best score (fewest guesses to win) persists across sessions.

Ne Zaman Kullanılır

  • 5-minute brain break with mathematical content.
  • Teaching kids about binary search — the strategy is dramatic and easy to demonstrate.
  • Demonstrating algorithmic thinking in interview prep or CS lessons.
  • Quick competitive game with a friend — race to the lowest guess count.

Ne Zaman Kullanılmaz

  • When you want randomness and luck — this is a pure deduction game; binary search wins every time.
  • When you want a long game — even with bad strategy, most rounds end in 5-10 guesses.

Yaygın Kullanım Senaryoları

  • Verifying a number or output before passing it on
  • Quick use during a typical workday
  • Pre-decision sanity-check on inputs and outputs
  • Educational use — demonstrating the underlying concept

Sık Sorulan Sorular

What's the optimal strategy?

Binary search. Start at 50; depending on higher/lower, halve the remaining range each guess. Guarantees a win in 7 guesses or fewer for any 1-100 target.

Why is the worst case exactly 7 guesses?

Because log₂(100) ≈ 6.64, rounded up to 7. With each guess, you halve the remaining range. After 7 guesses, the range is at most 100/2⁷ = 0.78, so it's definitely down to one number. This is the information-theoretic minimum for distinguishing 100 outcomes with binary feedback.

Can I always win in 7 guesses?

Yes if you play binary search optimally. Starting guess 50; if 'higher', next guess 75; if then 'lower', next guess 62 or 63 (halving 51-74); and so on. Exact mid-points sometimes round, but the 7-guess maximum holds.

What's the average for random guesses?

If you guess uniformly randomly without any strategy, around 13-15 guesses on average. Half-decent strategy (always picking the middle) gets you to 6-7 average. The difference is exactly the value of strategy in this game.

Are there variants?

Yes — 'Higher/Lower' is the universal name; some versions use 1-1000 (max 10 guesses), 1-50 (max 6), or unlimited range (you guess, system says higher/lower, with explicit upper bound shifting). The strategy stays the same: always halve.