Analysis of the 24 Game

The 24 Game is a very simple card game. Four cards are dealt at random, and the players must apply simple arithmetic operations to the four numbers on the cards; the goal is to obtain 24 as a result of these operations. Each of the four numbers must be used exactly once, and the available operations are addition, subtraction, multiplication, and division. For example, if the cards were (3, 1, 4, 1), a solution would be (1 + 1) * 3 * 4 = 24. In the simplest version of this game, we let A = 1, J = 11, Q = 12, K = 13, joker = 15. There are four cards of each normal denomination, and two jokers.

I was playing the 24 game on Friday night, and I claimed that fractions are not necessary in the 24 game; all problems in 24 that can be solved with fractions can also be done by division. After three examples to the contrary {(1, 5, 5, 5), (3, 3, 7, 7), (4, 4, 7, 7)}, I was forced to retract my claim. Fractions are indeed necessary to solve some hands of cards in 24. This leads to some interesting questions. First of all, how many hands require using fractions? How common is this type of hand?

To answer this question, I wrote a simple Python program to bash the 24 game. Admittedly, this program is terribly inefficient and a demonstration of bad coding style, but I think I’ve worked out the bugs. Given 3.5 minutes, my program can solve the 24 game entirely: It can generate every possible hand and give a solution for each (if a solution exists). The program can also determine if there exists a solution that does not require fractions.

Here’s a summary of the results of this program:

  • There are 2366 possible hands.
  • Out of these, 617 have no solution.
  • An additional 23 require using fractions to solve.

So we see that around a quarter of all hands are unsolvable, while less than 1% of hands require fractions. Thus, in most cases, it’s not necessary to consider fractional solutions; my claim was based on empirical evidence and is true for most hands. Indeed, I suspect that most people would give up on these problems in 24 and claim that they are unsolvable; that may explain why I hadn’t ever seen a solution involving fractions until Friday night.

I’ll admit that this isn’t precisely correct; not all hands are equally likely to appear; (3, 3, 3, 3) would appear much less often than (3, 4, 5, 6), for example. However, I assume that averaged over a large number of hands, this ratio of hands is approximately accurate. Thus, averaged over all impossible hands, I assume that impossible hands occur with probability around \frac{617}{2366} \approx 26\%.

Something that was discussed during Friday’s game was the idea of treating aces as 14 instead of 1. The rationale is that in most card games, aces are larger than kings. Under this new convention, what would be the probability of getting an impossible hand? My program computed 674 impossible hands, for an average impossibility rate of \frac{674}{2366} \approx 28\%.

This doesn’t seem like a big difference, but note that most hands don’t contain aces. What if we only looked at the impossibility rate of hands that contain aces? Here, the difference is a bit larger. There are 559 hands that contain aces, and when we set aces as ones, the probability that a random hand containing an ace has no solution is \frac{154}{559} \approx 28\%, while the probability when we set aces as fourteens is \frac{188}{559} \approx 34\%. Therefore, from a practicality standpoint, more hands are solvable when we set aces as ones. The difference isn’t huge, however, so both conventions for aces are reasonable.

If you’re interested, here’s a complete list of hands that require fractions in their solutions. It’s amusing to solve these “hardest” problems in 24, though they become much easier when it is known a priori that they require fractions.

(1, 3, 4, 6)
(1, 4, 5, 6)
(1, 5, 5, 5)
(1, 6, 6, 8)
(1, 8, 12, 12)
(1, 10, 12, 15)
(2, 2, 13, 13)
(2, 2, 11, 11)
(2, 3, 5, 12)
(2, 4, 10, 10)
(2, 5, 5, 10)
(2, 6, 10, 15)
(2, 6, 15, 15)
(2, 7, 7, 10)
(2, 7, 12, 15)
(2, 8, 12, 15)
(2, 9, 10, 15)
(3, 3, 7, 7)
(3, 13, 13, 15)
(4, 4, 7, 7)
(4, 4, 6, 15)
(5, 5, 7, 11)
(5, 7, 7, 11)


8 responses to “Analysis of the 24 Game

  1. Nic June 30, 2010 at 8:12 pm

    Cool! Been looking for something like this, Moor. Can you send me the program so I can tinker with it a little bit, please?


  2. Edmond October 22, 2011 at 10:19 am

    Insightful analysis, Moor! I’m curious how you can solve (3,3,8,8) without using fractions? (There is a solution with fractions). Thanks!

  3. Carlos October 26, 2012 at 8:29 am

    Other than 3 3 8 8, you got all other fractions.

    Here is a list for regular cards (<=13)

  4. Mitch June 17, 2013 at 7:45 pm

    I had built my own solver both in Python and Java.
    The first time I ran it I too got the same results as you, then I realized that some were missing, e.g. 3, 3, 8, 8.
    The problem is purely binary exactness I think. any way the closest my solver got to 24 was 23.999999…
    In the end I created a closeTo function that said if a number was within 10**-6 of 24, then it probably meant 24.
    The end results are that 3 impossible combos become requiring fractions. The other 2 are (1,8,10,15) and (1,9,9,15).
    Total: 2366
    Require Fractions:26

  5. anonymous June 1, 2014 at 6:00 pm

    there is a variation of the 24 game using 6 cards and a goal of 163 instead of 24. At first, the game seems much more difficult, but in fact, i’ve observed that a higher proportion of games can be solved than in 24. I’d be curious to see the actual numbers comparing them though.

  6. pi July 18, 2014 at 5:41 pm

    Do you ever play with exponentiation, square roots, and factorials (!)? With those, I think the unsolvable list should shrink to zero. For example, (3,3,8,8) is (sqrt(3×3) + 8/8)! and (1,8,10,15) is 15 + 8 + 1^10 etc

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: