🔢 Number Guessing Game (1-100)
📐 工作原理與說明
目標數 = floor(隨機數 × 100) + 1,即 1 到 100 的閉區間整數;開局重置嘗試次數與猜測歷史並顯示遊戲區,提示輸入 1–100 之間的數字
A number from 1 to 100 is chosen at random; you guess and get higher/lower hints, with the number of attempts and your best score tracked.
點選"開始"按鈕開始遊戲
📚 深度解析:猜數字遊戲(1-100)
💡 常見使用場景
- 邏輯推理:根據偏大、偏小提示逐步逼近答案。
- 演算法教學:演示二分查詢最壞 ≤7 步。
- 記錄成績:統計猜測次數與最佳。
方法(二分策略)
每次猜區間中點把範圍砍半;最壞步數 = ⌈log2(100)⌉ = 7。記錄次數與最佳成績。
算例(演示)
答案 42:猜 50(小了)→25(大了)→37(小了)→43(大了)→40(小了)→42(中),6 步命中。理性二分穩定 ≤7 步,盲猜平均約 50 步。
❓ 常見問題(FAQ)
- 為什麼最多 7 步?
- 2^7=128>100,每步砍半 7 次足以區分 100 個數,資訊理論下界。
- 和 caishuzi-1-100fanwei 區別?
- 同源同類,均 1-100 二分猜數;caishuzi 頁面側重範圍提示文案,本工具側重次數記錄。
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Binary search | halving the range needs at most the ceiling of log base two | Search algorithms |
| Range of one hundred | a range of one hundred resolves within seven guesses | Search algorithms |
| Feedback | only higher or lower is returned, so interpolation does not help | Search algorithms |
⚠️ 使用說明與注意事項
- 本工具純前端執行,資料不會上傳到伺服器
- 建議在主流瀏覽器(Chrome/Safari/Firefox/Edge)中使用
- 計算結果僅供參考,請以實際應用場景為準