# Number of 5-card Charlie hands in blackjack

A five-card Charlie in blackjack is when you have a total of 5 cards and you do not exceed a point total of 21. How many such hands are there? Of course, the natural next question concerns six-card Charlies, etc.

It seems like one way of determining the answer might be to determine the total number of 5-card hands and then subtract out the number of hands that exceed 21, but I am at a loss as to how to do this effectively. Is there some use of the inclusion-exclusion principle at work here? The condition that the cards do not exceed 21 is the difficulty I am having a hard time addressing. Any ideas?

• Are you familiar with Diophantine equations? It's a broad subject, and I know nothing about blackjack, but if I read you correctly, the simplest diophantine equations will help you solve this. – The Count Mar 12 '17 at 19:59
• @TheCount Familiar at the most basic level, which may explain why I'm having a difficulty making the connection. But I'll definitely try to put the pieces together! Thanks for the possible hint. Any help is always appreciated. – interrogative Mar 12 '17 at 20:03
• Sure. Good luck! The solutions in integers to $a+b+c+d+e\leq 21$ is a form of diophantine problem... I'm almost sure... Ha. – The Count Mar 12 '17 at 20:04
• @TheCount: The question is more difficult than that. One reason is that there are at most 4 cards of a given denomination less than 10. So the solution a=b=c=d=e=1 of your equation is not a five-card Charlie. There are also the complications that there are 16 cards with value 10, not the usual 4 cards, and that swapping out say the 2 of clubs with the 2 of diamonds is a different hand but the same solution to your equation. – Rory Daulton Mar 12 '17 at 23:01
• @RoryDaulton Okay, sure, but that doesn't mean it won't work. It means a few tweaks are in order. – The Count Mar 13 '17 at 1:40

Here is an answer by brute force enumeration of all 5-card hands, using an R program: the number of 5-card Charlie hands is 139,972.

deck <- c(rep(1:9, 4), rep(10, 16))
acceptable <- function(x) {sum(x) <= 21}
sum(combn(deck, 5, acceptable))


One way to classify all blackjack hands is with a generating function: $$\left((x y+1) \left(x^2 y+1\right) \left(x^3 y+1\right) \left(x^4 y+1\right) \left(x^5 y+1\right) \left(x^6 y+1\right) \left(x^7 y+1\right) \left(x^8 y+1\right) \\ \left(x^9 y+1\right) \left(x^{10} y+1\right)^4\right)^4$$ Here, the coefficient of $x^a y^b$ gives us the number of hands that add up to $a$ and contain $b$ cards. (Assuming that all aces are worth $1$.)

So we can use the following Mathematica code to extract the information we want.

First, define the generating function above:

gf = ((1 + x y) (1 + x^2 y) (1 + x^3 y) (1 + x^4 y) (1 + x^5 y) (1 + x^6 y) (1 + x^7 y) (1 + x^8 y) (1 + x^9 y) (1 + x^10 y)^4)^4;


Next, take the coefficient of $y^5$ to only look at $5$-card hands:

poly = Coefficient[gf, y^5];


Extract a list of the coefficients of $x$: this has the number of hands with each possible value.

coeffs = CoefficientList[poly, x];


Finally, add up the first $22$ coefficient (the values $0$ through $21$).

Total[coeffs[[1 ;; 22]]]


The second line can be modified in the obvious way to get different hand sizes.

• This assumes that there is only deck, most casinos will have 4 or 6 decks - how would that change the answer? – user144464 Jul 31 '18 at 19:28
• The outermost power of $4$ tells us that there are $4$ copies of every card in the deck. If we are using $4$ combined decks, then there are $16$ copies of every card in the deck, instead. – Misha Lavrov Aug 1 '18 at 0:14

The total number of 5-cards hands with a 52-cards deck is $${52 \choose 5}=\frac{52!}{5!(52-5)!}=2598960$$ Really not so many possibilities out there, so the brute force method is quite fast, so i've implemented it (in Mathematica).
First of all, let's create the deck:

deck = Flatten[ConstantArray[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10}, 4]]


In this way

deck: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10\}


Then we want to generate all possible subsets (hands) with exactly 5 cards, and make sure that the code is right counting how long is the array "hands".

hands = Subsets[deck,{5}]; (* Semicolon for suppressing long output *)
Length[hands]


Then we want to get the total for each hand, and "tally" the list of the total.

sums = Total[hands,{2}]; (* {2} is an option to tell mathematica to do the sums in the sublist (2-nd level of a list) *)
Tally[sums]


Or, if you want a one-line command:

Tally[Total[Subsets[Flatten[ConstantArray[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10}, 4]], {5}], {2}]]


And the sorted output is:

{{6,4},{7,28},{8,92},{9,240},{10,484},{11,920},{12,1552},{13,2492},{14,3784},{15,5724},{16,8344},{17,11988},{18,16520},{19,22144},{20,28948},{21,36708},{22,45584},{23,55712},{24,67600},{25,79416},{26,92416},{27,103808},{28,115520},{29,125188},{30,134052},{31,140224},{32,146936},{33,149268},{34,147784},{35,143676},{36,136344},{37,127484},{38,116832},{39,105176},{40,92548},{41,82176},{42,65532},{43,52556},{44,40436},{45,31216},{46,22496},{47,16720},{48,10640},{49,7280},{50,4368}}


It menans that there are four hand that sums to 6 ( whan you have all the aces and a two).

It's not human-readable, it is? So let's do a good looking excel histogram!

In the image, the total height of all the red columns is the number of five-card Charlie. The number can be computed by:

Count[hands, u_ /; Total[u] <= 21]


That is: $$139972$$

Just because i'm fond of one-line command:

Count[Subsets[Flatten[ConstantArray[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10}, 4]], {5}], u_ /; Total[u] <= 21]

• You forgot that Queens and Jacks and such have a value of $10$ – Stan Tendijck Jul 20 '18 at 8:54
• yup... just edited – Luca Savant Jul 20 '18 at 8:55

Generating Functions

For those who may not have fully grasped the power of generating functions in solving combinatorial problems, I highly recommend going through @Misha's solution line-by-line (and then upvote it).

To those who may be new to combinatorics, the use of generating functions to solve problems may seem like almost magic. It allows an extremely large number of popular problems that appear difficult, to be solved very quickly.

Some gentle introductions to generating functions can be found by Levin, and by Meyer and Rubinfeld, and of course at Wikipedia.

Furthermore, here are some other questions on Stack Exchange which can be solved elegantly through generating functions:

Charlie Hands

The generating function for this problem is: $$(x y+1)^4 \left(x^2 y+1\right)^4 \left(x^3 y+1\right)^4 \left(x^4 y+1\right)^4 \left(x^5 y+1\right)^4 \\\left(x^6 y+1\right)^4 \left(x^7 y+1\right)^4 \left(x^8 y+1\right)^4 \left(x^9 y+1\right)^4 \left(x^{10} y+1\right)^{16}$$

The key to this generating function, and generating functions in general, is that:

• when powers of $x$ are multiplied, their exponents are summed (and similarly for $y$);
• the $x$ component is tracking the point value contribution of each particular card, and the $y$ powers are tracking the count of that particular card;
• the $+1$ in each $(\cdot )$ term can be thought of as $x^0y^0$. (That is, that card was not selected, and thus contributes zero to the point total.)
• the exponent of 4 is because there are 4 suits for each card value, and
• the exponent of 16 is because there are 16 cards that have a value of 10.

So putting all these points together:

If the generating expression were fully expanded out, the co-efficient of the term $x^a y^b$ is the number of hands comprising of exactly $b$ cards and have a point total of exactly $a$.

Therefore, as per @Misha's code (with only a minor modification),

charlieCnt[k_]:=
(
gf = ((1+x y) (1+x^2 y) (1+x^3 y) (1+x^4 y) (1+x^5 y) (1+x^6 y) (1+x^7 y)
(1+x^8 y) (1+x^9 y) (1+x^10 y)^4)^4;
poly = Coefficient[gf,y^k];
coeffs = CoefficientList[poly,x];
Total[coeffs[[1;;Min[22,Length@coeffs]]]]
);


We can now create the table below, which gives the number of Charlie hands of size, $k$.

For further context, the table also shows $\binom{52}{k}$, the total number of hands of size $k$.

The final column is the fraction of all possible $k$-card hands that are Charlie hands.

$$\begin{array}{c|r|r|r|} k & \text{Charlie hands} & \text{All hands}& \text{fraction} \\ \hline 1 & 52 & 52 & 1\\ \hline 2 & 1326 & 1326 & 1 \\ \hline 3 & 13740 & 22100 & 0.62 \\ \hline 4 & 61269 & 270725 & 0.23\\ \hline 5 & \bf{139972} & 2598960 & 5.3 \times 10^{-2} \\ \hline 6 & \bf{173982} & 20358520 & 8.5 \times 10^{-3}\\ \hline 7 & 121960 & 133784560 & 9.1 \times 10^{-4}\\ \hline 8 & 47404 & 752538150 & 6.3 \times 10^{-5}\\ \hline 9 & 9052 & 3679075400 & 2.4 \times 10^{-6} \\ \hline 10 & 610 & 15820024220 & 3.9 \times 10^{-8} \\ \hline 11 & 4 & 60403728840 & 6.6 \times 10^{-11}\\ \hline 12+ & 0 & \ldots & 0\\ \hline \end{array}$$

Thus, the number of 5-card Charlie hands is 139972, and the number of 6-card Charlie hands is 173892.

This table also helps explain why the Blackjack house rules often include special rules and payouts for 5-card and 6-card charlies but not for more cards. That is, the probabilities for $k=5$ or $6$, are small enough to offer interesting odds, but still large enough that there is a reasonable likelihood of happening some time in an entire game.

Drilling down

Note that the last line of the Mathematica code above, simply sums up the first 22 coefficients. However, by considering these terms separately, we get the number of $k$-card Charlie hands that have a points total of exactly $T$.

$$\begin{array}{c|r|} &1 &2 &3 &4 &5 &6 &7 &8 &9 &10 &11 &12 &13 &14 &15 &16 &17 &18 &19 &20 &21 &\bf{\text{All}} \\ \hline \bf{3} &0 &0 &4 &24 &48 &92 &136 &200 &268 &352 &440 &620 &824 &960 &1124 &1216 &1336 &1388 &1464 &1472 &1772 &\bf{13740} \\ \hline \bf{4} &0 &0 &0 &1 &16 &52 &128 &245 &416 &664 &976 &1385 &1936 &2780 &3696 &4909 &6064 &7456 &8784 &10225 &11536 &\bf{61269} \\ \hline \bf{5} &0 &0 &0 &0 &0 &4 &28 &92 &240 &484 &920 &1552 &2492 &3784 &5724 &8344 &11988 &16520 &22144 &28948 &36708 &\bf{139972} \\ \hline \bf{6} &0 &0 &0 &0 &0 &0 &0 &6 &32 &124 &320 &734 &1472 &2698 &4624 &7570 &12016 &18506 &27872 &40424 &57584 &\bf{173892} \\ \hline \bf{7} &0 &0 &0 &0 &0 &0 &0 &0 &0 &4 &28 &112 &324 &816 &1756 &3500 &6412 &11244 &18808 &30708 &48248 &\bf{121960} \\ \hline \bf{8} &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &1 &16 &68 &240 &649 &1568 &3360 &6688 &12494 &22320 &\bf{47404} \\ \hline \bf{9} &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &4 &28 &116 &368 &1004 &2368 &5164 &\bf{9052} \\ \hline \bf{10} &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &6 &32 &140 &432 &\bf{610} \\ \hline \bf{11} &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 &0 4 &\bf{4} \\ \hline \end{array}$$

Comparative Note

Most responding answers to this question have, quite correctly, stated that for a 5-card hand there are only $\binom{52}{5} = 2598960$ possibilities, which is small enough that enumerating all of subsets and then counting/selecting those whose total is $\leq 21$, takes only a few seconds on today's computers.

However, what the first table clearly shows is that the number of combinations explodes as $k$ increases. For example, $k=9$ has more than 1600 times as many combinations as $k=5$. Therefore these brute force methods get exponentially slower as $k$ increases, and so are often very ineffective if used to calculate the number of Charlie hands for more than,say, 9 cards.

In contrast, calculating the total number of $k$-card Charlies hands via generating functions takes less than a fraction of a second for all values of $j$ even as high as 11.

Final note

The above table gives the total number of distinct Charlie hands, of size $k$. However, in practice, these values really only represent an upper bound, due to a subtle counting issue related to the aces.

Even assuming a fully shuffled deck etc, there are a large number of hands included in these counts, which in practice, are far less likely to be encountered than the rest. The issue lies in the fact that all the answers so far all answers have assumed that the value of an Ace is always 1. However, in Blackjack, the player can choose whether it is a 1 or an 11. This causes a subtle problem with counting Charlie hands which can be seen in the follow examples:

• If the player's first two cards were an ace and a king, then they would have a 'blackjack' 21. In this situation it is almost certain that they would not request another card. Thus, all 5-card Charlie hands, where the first two cards are an ace and king, are almost certainly never going to be seen.

• if the player's first three cards were: a Four, an Ace, and a Six. Again, they have 21, and so it possible but quite unlikely that they would 'hit' for another card. Thus 5-card Charlie hands beginning like this would be unlikely to be seen.

• if the player's first four cards were: An ace, two 2s, a 3 and a 4. Again, although they have 21, they may (or may not) might be feel daring and 'hit' for another card.

Thus, for a pragmatic lower bound on the number of distinct $k$-card Charlie hands that could be seen in an actual game, we should probably subtract from the figures in the first table, the count of all those Charlie hands of size $k$, where the player reaches 21 via an ace before the final $k$-th card is drawn.

• Great response - I have a question, this assumes that there is only deck, most casinos will have 4 or 6 decks - how would that change the answer? – user144464 Jul 31 '18 at 19:28

Here's a recursive Java code

public class MSE2183749 {
// counts hands (with permutations) attaining at most t1 points, from n cards
public static long countp(final int t1, final int n, final int[] cards) {
if (n > t1)         return 0;
if (n == 0)         return 1;
long ac = 0;
for (int j = 1; j < cards.length && j + n - 1 <= t1; j++) {
if (cards[j] == 0)  continue;
int[] cards2 = Arrays.copyOf(cards, cards.length);
cards2[j]--;
ac += cards[j] * countp(t1 - j, n - 1, cards2);
}
return ac;
}

public static void main(String[] args) {
long res = countp(21, 5, new int[] { 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 16 });
System.out.println(res/(5*4*3*2));
}
}


The result, as other answers have pointed out, is 139972