Enter four numbers (typically 1–13) or click Random to generate them. Find every way to make 24 using addition, subtraction, multiplication, division, and parentheses. Multiple solutions are displayed instantly.
The 24 Game is an arithmetical puzzle where the goal is to combine four integers (usually from 1 to 13) using the basic operations (+, –, ×, ÷) to obtain 24. Parentheses can be used to change the order of operations. For example, with 3, 3, 8, 8, a classic solution is 8 ÷ (3 – 8 ÷ 3) = 24. The game sharpens mental arithmetic and strategic thinking.
Given four numbers a, b, c, d, find an expression E(a,b,c,d) = 24 using +, –, ×, ÷ and parentheses.
The 24 Game was invented by Robert Sun in 1988 and first published by Suntex International. It quickly became a classroom favorite for building mental math skills. Today it is played worldwide, with tournaments and online versions. The game’s depth lies in its simplicity: some sets have no solution (e.g., 1,1,1,1), while others have dozens. It naturally introduces fractions, factoring, and order of operations.
Our solver uses a recursive brute‑force algorithm that considers all ways to combine the numbers. It generates every binary tree structure (5 distinct shapes for 4 numbers) and all permutations of numbers (4! = 24) and operators (4³ = 64). For each combination it evaluates the expression using exact rational arithmetic to avoid floating‑point errors. The result is checked against 24 within a tiny epsilon (1e‑10). All unique expression strings are collected and displayed. Duplicates due to commutativity (e.g., a+b and b+a) are filtered to present a clean list.
Search space: 4! × 4³ × 5 = 24 × 64 × 5 = 7680 candidate expressions. The solver runs in milliseconds.
All examples can be verified with the solver.
| Numbers | Sample Solution | Strategy |
|---|---|---|
| 1,4,5,6 | 4 ÷ (1 – 5÷6) = 24 | Fraction complement |
| 1,3,4,6 | 6 ÷ (1 – 3÷4) = 24 | Fraction complement |
| 2,3,5,6 | (5 – 2) × 6 + 6 = 24 | Make 18+6 |
| 4,4,4,4 | 4×4 + 4 + 4 = 24 | 16+8 |
| 3,5,7,9 | (7×5) – 9 – 3 = 35 – 12 = 23? Actually (7-5)×9+3 = 2×9+3=21; (9-7)×5+3=2×5+3=13; one real solution: (3×9) – (7-5) =27-2=25; no 24? The solver will show if any. | Varied |
Ms. Rodriguez, a 5th‑grade teacher, uses the 24 Game to reinforce PEMDAS. She projects the solver to show multiple solution paths for the same set, e.g., {2,3,4,5}. Students see that (2+3-5)×4! is not allowed (factorial not permitted) but they discover (5+3-2)×4 = 24. The tool helps them verify their ideas instantly and promotes discussion about why certain expressions work.
Approximately 1% of all quadruples of numbers 1–10 have no solution. Famous impossible sets include {1,1,1,1}, {1,1,1,2}, {1,1,1,3}. The solver will clearly indicate when no expression equals 24.
function solve24(nums, exprs) {
if (nums.length === 1) {
if (Math.abs(nums[0] - 24) < 1e-10) solutions.add(exprs[0]);
return;
}
for (let i = 0; i < nums.length; i++) {
for (let j = i+1; j < nums.length; j++) {
let a = nums[i], b = nums[j];
let newNums = nums.filter((_, idx) => idx !== i && idx !== j);
let newExprs = exprs.filter((_, idx) => idx !== i && idx !== j);
const ops = [
[a+b, `(${exprs[i]} + ${exprs[j]})`],
[a-b, `(${exprs[i]} - ${exprs[j]})`],
[b-a, `(${exprs[j]} - ${exprs[i]})`],
[a*b, `(${exprs[i]} × ${exprs[j]})`],
[a/b, `(${exprs[i]} ÷ ${exprs[j]})`, b !== 0],
[b/a, `(${exprs[j]} ÷ ${exprs[i]})`, a !== 0]
];
for (let [val, expr, valid=true] of ops) {
if (!valid) continue;
solve24([...newNums, val], [...newExprs, expr]);
}
}
}
}