🧩 24 Game Puzzle Generator

24-point puzzle generator: produces the requested number of arithmetic puzzles solvable to 24 using addition, subtraction, multiplication and division.

📐 工作原理與說明
求解:從陣列中任取兩個不同元素 a、b,用 + − × 及(|b| > 1e-6 時的 ÷)合成新元素,與剩餘元素遞迴;單元素時 |v − 24| < 1e-6 判命中並回傳表示式串。出題:從 1-10 隨機取 4 個數,最多試 2000 次直到有解,兜底 [3,3,8,8] 解 (8/(3−8/3))
本工具用於數字謎題生成(24點遊戲)的即時計算,依據對應公式與標準運算規則處理,結果按精度即時輸出;純前端執行,資料不上傳。

📚 深度解析:24 點遊戲出題(四數湊 24)

💡 常見使用場景

  • 腦力遊戲出題:隨機發 4 張 1~13 的牌,保證存在 +−×÷ 湊 24 的解
  • 教學訓練:練習四則運算與括號組合
  • 親子/課堂:可設定難度與是否含分數
方法
用法:工具自動生成 4 個 1~13 的整數,且至少存在一種四則運算(可加括號)得 24;玩家找出表示式。
算例
例:發牌 [3,3,8,8] → 8/(3−8/3)=8/(1/3)=24。發牌 [1,5,5,5] → 5×(5−1/5)=5×4.8=24。每局解不唯一,可多人比速度。

❓ 常見問題(FAQ)

一定會有解嗎?
出題保證有解(生成時回溯驗證);若出現無解組合會被排除重發。
能用分數中間結果?
標準 24 點允許運算中出現分數(如 8/3),只要最終為 24;部分變體限制整數中間值。

Formula & Standard References

Item Formula / Note Source / Standard
Operator space four numbers, three operators and brackets give a few thousand cases Combinatorial enumeration
Solvability precheck verify solvability by enumeration before presenting a puzzle Combinatorial enumeration
Difficulty tiers grade by solution count and whether fractional steps are needed Puzzle design practice
⚠️ 使用說明與注意事項