🔢 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)中使用
- 计算结果仅供参考,请以实际应用场景为准