# All Legal combinations of digits For the 24 Game

The rules of our 24 game are based on the original card game, and quite simple:

Take 4 integers between 0 and 9, and by joining them with parentheses () and the 4 arithmetic symbols (+,-,×,÷) only, formulate an equation that gives 24.

My mother and I used to compete and see who could work out 24 using passing cars’ license plates the fastest. But then we came to a country where the majority of cars have only 3 digits in their license, so this game is no longer playable, and I am happy to ruin the fun for good (for myself).

This page lists all legal combinations of numbers (sorted) using which you can work out 24. It is sometimes still a nontrivial challenge to find the actual solution, though. In Year 7 my math teacher asked me how to get 24 using 3, 3, 7, and 7, to which I confidently answered “there’s no solution!”.

I was wrong. 24 = (3 + 3÷7) × 7.

(Also my Python code is in no way optimized… so you can write your own in minutes. Also this version does not account for powers or roots.)