24 Game

About

24 is an arithmetic puzzle game where you add, subtract, multiple, and divide four numbers to find 24 . This is an implementation of the game that allows for generating random games as well as solving any games.

Ways To Play

You can, of course, play the game by going to the home page and creating a new game. This will generate a new random game and allow you to find your own solutions or click the "Solve" button to find available solutions. You can also go to the solve page to find solutions for puzzles that you find in other contexts, such as playing with a deck of playing cards or any other source of random integers.

How Solutions are Computed

For each input of four numbers, all possible unique orderings are found; then all possible unique orderings of three operations (out of addition, subtraction, multiplication, and division) are found. The cartesian product of those two sets is then used to generate all possible candidate solutions. Each is then computed and check to see whether it results in 24 .

The program tries to reduce the number of repetitive solutions by removing those that are equivalent by the distributive and associated properties of addition and multiplication; though, solutions with different operations or different grouping of operations are not necessarily removed from this de-duplication step. This should result in a reasonable and intuitive set of solutions.

Why are some solvable inputs considered unsolvable?

To avoid returning an overwhelming number of solutions, there are some simple rules applied to division and subtraction to prohibit certain situations. Subtraction is prohibited when the result would be negative. Division is prohibited when the result would have a remainder. These rules do prevent certain inputs from being solvable (for example, 3 3 8 8 ).

License

24 is a widely known arithmetic puzzle game. This is an implementation of that game. This implementation is licensed under the MIT License and its source code is available on GitHub at laurelmay/24game.