A simple Python command-line application that solves the classic 24 Game.
The program takes 4 numbers as input and finds a mathematical expression that equals 24.
- Solve the 24 Game using 4 input numbers
- Supports addition, subtraction, multiplication, and division
- Uses exact fraction calculation to avoid floating-point errors
- Colorful terminal interface using Rich
- Allows repeated input until the user exits
Enter your number here! ⭐ : 4 4 6 0Your solution is (4 * (6 + 0)) = 24If no solution is found, the program will display:
No solution found for these numbers.Clone this repository:
git clone https://github.com/YOUR_USERNAME/24-game-solver-cli.git
cd 24-game-solver-cliInstall dependencies:
pip install -r requirements.txtRun the program:
python main.pyThen enter 4 numbers separated by spaces:
4 4 6 0To exit the program, type:
exitor
quitThe program tries every possible combination of the 4 numbers with basic arithmetic operators:
- Addition
- Subtraction
- Multiplication
- Division
It recursively combines numbers until only one result remains.
If the result equals 24, the program returns the expression.
- Python 3.8+
- Rich
24-game-solver-cli/
│
├── main.py
├── README.md
├── requirements.txt
├── LICENSE
└── .gitignore
This project is licensed under the MIT License.