A simple solver for the classic 24 Game.
It takes 4 digits (1–9) and tries to make the number 24 using the basic math operators: + - * /
.
The 24 Game is a math puzzle played with 4 numbers.
Rules:
- Use all 4 numbers exactly once.
- Only 1 - 9 numbers allowed.
- You can use the operations
+ - * /
. - Parentheses can be added anywhere to control the order of operations.
- The goal: make the result equal 24.
Example: with numbers 3, 3, 8, 8
→ one valid solution is (8 / (3 - 8/3)) = 24
.
This program automates the search for all possible valid solutions.
While the solver removes obvious duplicates, some results may still look similar because of different parenthesis placements or mathematically equivalent expressions.
- Make sure Go is installed.
- Clone this repository:
git clone https://github.com/x0root/24Solver.git cd 24Solver
- Run the solver:
go run main.go
- Enter 4 digits (example:
1 2 3 4
or1234
), and the program will search for all valid solutions.
Contributions are welcome. You can help with:
- Bug fixes
- Code optimization
- New features (e.g. more operators, GUI, or testing)
Fork the repo, create a branch, and open a pull request. Suggestions and discussions are also encouraged.
This project is licensed under the MIT License — see the LICENSE file for details.