24 Game Solver

Coding · Medium · Free problem
Given four numbers (integers or fractions), determine whether you can combine them using the four basic operations ($+$, $-$, $\times$, $\div$) and parentheses to obtain exactly
4$. Each number must be used exactly once. For example, given $[1, 2, 3, 4]$, one valid expression is
\times 2 \times 3 \times 4 = 24$. Write a function that takes a list of four numbers and returns `True` if 24 can be made, `False` otherwise. **Constraints:** - Input is a list of exactly 4 positive numbers - You may use $+$, $-$, $\times$, $\div$ (real-valued division) - Parentheses can be placed anywhere - Each number is used exactly once **Examples:** - Input: `[1, 2, 3, 4]` -- Output: `True` (e.g.,
\times 2 \times 3 \times 4$) - Input: `[8, 3, 8, 3]` -- Output: `True` (e.g., $8 / (3 - 8/3) = 24$) - Input: `[1, 1, 1, 1]` -- Output: `False`

Open the full interactive solver, hints, and worked solution →