Every now and then I like to play a game of poker.
Hands, in poker, are ranked according to the basic chances of them occurring. Those hands that would randomly occur with a lower frequency rank higher than those that are more likely to occur. In the most vanilla form of poker, five cards are dealt to make a hand. The hand rankings for five card poker are shown in the table below.
A standard deck of playing cards contains 52 cards, and these can be arranged to make a total of 2,598,960 distinct sets of five cards.
Mathematicians often write this number as 52C5 (spoken as “52 choose 5”). It's a measure of the ways that five cards can be selected from 52 cards without replacement, and not worrying about their order.
The calculation of these choices (also called combinations) are the number of ways that k items can be picked from a set of n items in an unordered way. It can be calculated using the following formula:
If five cards are dealt, to the left is the table of all the ranks and the frequencies of them occuring. The highest ranked hand is the straight flush. In a straight flush, all cards are of the same suit (flush), and they are numerically connected in order (straight). If there is more than one straight flush, the value of the highest card is compared.
Many poker enthusiasts call out the very highest possible Straight Flush: A-K-Q-J-10 and give it the special name of a Royal Flush, but there is no real reason to do this as it's simply a higher version of a regular straight flush.
Even though there are 40 possible straight flushes, there are only four possible royal flushes. One for each suit.
It's a fun exercise to see how we can mathematically derive all the above frequency numbers.
For a straight flush, not only do the cards need to be of the same suit, but they all need to be numerically connected. There is only one of each card of each suit. The highest possible straight flush ends with an Ace. The next highest ends with a King, then a Queen, all the way down to the run ending with a five. In poker the Ace can be used either as a high-card, or a low-card (but not both types in the same hand, so it's not possible for a straight to roll over the top).
This means there are ten possible straight flushes in any suit: A-K-Q-J-10, K-Q-J-10-9, Q-J-10-9-8 … 5-4-3-2-A
(The lowest straight is also given the vernacular name of a Wheel).
Ten possible straights in each suit, and four suits, results in 40 possible straight flushes out of the 2,598,960 hands.
Another way to calculate this is to say we have 10C1 × 4C1 (Ten possible choices for the first card, and four possible suits).
Four of a kind
To get four of a kind we have, as the name implies, four of one kind, then a singleton. As there are only four of any number, this singleton can by any of the other non-used cards.
There are thirteen different cards that can be used for the quads: A,K,Q,J,T … 3,2, this leaves 48 other cards for the singleton. So the number of possible hands is 13 × 48 = 624.
Another way to calculate this is to say we have 13C1 × 48C1 (Thirteen possible choices for the quads card, and forty-eight possible choices for the singleton).
In a full house, there are three of one kind of card, and two of another. There are thirteen possible cards that can be used for the triple, leaving twelve possible (different) cards that can be used for the pair. For the triple, as there are three cards, there are 4C3 different combinations of the cards (An easy way to think of this is that this has to be four: If you are selecting three cards, there are four ways, one for each suit that is missing).
After the triple, there are twelve possible cards that can be selected as the pair.
There 4C2 ways the suits of the twelve possible pairs can be arranged.
So the number of full houses possible is: 13C1 × 4C3 × 12C1 × 4C2 = 13 × 4 × 12 × 6 = 3,744.
This one gets a little more complicated, but there's a little trick, and we can leverage a previously calculated answer.
For a flush, all the cards are the same suit. Let's pick the suit first. There are 4C1 choices.
There are 13 cards in a suit, and from these, we need to pick any 5, so this would have been 13C5, however if we do this we'll be double counting a straight flush (where all the cards are in numeric order). We have, however, already determined there are forty straight flushes, so all we have to do is subtract this number of straight flushes from all the flushes.
Flushes: (4C1 × 13C5) − 40 = (4 × 1,287) - 40 = 5,108.
The calculations for a vanilla straight is a little more complex.
As from above there are ten possible cards that the highest card of the straight can be. This card can be any one of the four possible suits, so as a starting point there are 10 × 4C1 = 40 possible top cards of any straight.
After this card, the numeric value of each subsequent card below is already defined; the only variable is suit, and there are 4C1 ways each next card can be selected. The last step, as above, is to subtract out the number of straight flushes, to stop the double count if all the cards in the straight have the same suit.
Straight: ((10 × 4C1) × 4C1 × 4C1 × 4C1 × 4C1) - 40 = 10 × (4C1)5 - 40 = (10 × 1,024) - 40 = 10,200.
Three of a kind
Things are getting a little more complex. For three of a kind, we can have any of the thirteen possible numbers for the triple (just like the start of the full house), but for the two remaining cards, not only do they need to be different from the triple, they need to be different from each other (otherwise they set would be a full house). We don't care what the suit of these last two cards are, so there are 4C1 ways for each of these singletons.
Three of a kind: 13C1 × 4C3 × 12C2 × (4C1)2 = 13 × 4 × 66 × 16 = 54,912.
For two pairs there are thirteen possible values that each of the pairs could have, and from these we need to select two 13C2. Each of these pairs can be made from two differenent suits 4C2. The singleton can have a value of any of the other unused 11 cards 11C1, and be any one of the suits 4C1
Two Pair: 13C2 × (4C2)2 × 11C1 × 4C1 = 78 × 36 × 11 × 4 = 123,552.
To get a hand with a pair there are thirteen possible values for the paired card 13C1, and this can happen in 4C2 suited ways. The remaining three cards can be any suit, and we need to select this card from the remaining 12, so 12C3 cards each one of them 4C1 suits.
Pair: 13C1 × 4C2 × 12C2 × (4C1)3 = 13 × 6 × 220 × 64 = 1,098,240.
In theory, we don't need to calculate this value. Paraphrasing Sherlock Holmes; once we've eliminated the impossible, whatever left is the solution. We know the total number of possible sets is 2,598,960 and we've calculated the occurences of all the other possible hand rankings. If we add up all the other ranking hands and subtract this from the total number, we should be left with the number of hands which have nothing but a high card.
However, since we like the challenge (plus it's good verify), here's the calculation.
Because the values of the card have to be distinct (not even a pair), there are 13C5 basic ways these values can be selected. Let's assume, for now, that each of these cards can be any suit.
We're almost home. From this value we subtract away the number of straights, flushes, and straight flushes.
High card: 13C5 × (4C1)5 - 40 - 5,108 - 10,200 = (1,287 × 1,024) - 40 - 5,108 - 10,200 = 1,302,540.
Another way to calculate this value is to start with the 13C5 ways to get five values and from that subtract the 10 we know are the only straights. This gives us the values of the cards. Then we need to look at the suits. Each of the cards can be any the suits, with the exception of the four times when the suits all align and it would be a flush.
Alternative High card calculation (13C5 - 10) × ((4C1)5 - 4) = (1,287 - 10) × (1,024 - 4) = 1,302,540.
Thankfully all our possible hand combinations add up to 2,598,960. Phew!
A standard deck of cards has four suits. Because of this, a full house occurs less frequently than a flush, which in-turn occurs less frequently than a straight. What would happen if there were less suits in a deck, or more suits?
This is an interesting thought exercise. If we had a 'skinny' deck with just three suits (or maybe even two?), then flushes would become much more common. Taken to the limit, if there was just one suit, then every hand would be a flush!* How would the other probabilities change?
An added complication is that, with more than five suits it is possible to get a new hand type: Five of a Kind!
*Or a straight flush!
Going the other way, what if cards could have more than 13 different values? The higher the number of cards in a deck, the harder it would be to make straights. If we say that Jack=11, Queen=12, and King=13 how would the probabilities change if there were 15 distinct cards for each of the four suits? How about 20?
How about if we combined both these and varied both the number of suits and the range of the cards?
Leveraging what we've learned above it's possible to derive generic formulae for the number of occurences of each of these hands.
If S is the number of suits in a deck, and V is the range of values, then here are the generic formulae for the number of hands:*
|Five of a kind||VC1 × SC5|
|Straight Flush||V-3C1 × SC1|
|Four of a kind||VC1 × SC4 × VS-SC1|
|Full House||VC1 × SC3 × V-1C1 × SC2|
|Flush||(VC5 × SC1) - (V-3C1 × SC1)|
|Straight||(V-3C1 × SC15) - (V-3C1 × SC1)|
|Three of a kind||VC1 × SC3 × V-1C2 × SC12|
|Two Pair||VC2 × SC22 × V-2C1 × SC1|
|Pair||VC1 × SC2 × V-1C3 × SC13|
|High Card||(VC5 - (V-3)) × (SC15 - S)|
*The formula for straights is only correct for V ≥ 6 (because we need to take account that the Ace can be used at either end). If V = 5, we need to subtract 4 from the number of choices to pick from, not 3.
Below are the how the rankings change if we keep the number of values in a deck fixed at 13 (A,K,Q,J,T,9,8,7,6,5,4,3,2) and vary the number of suits in the deck. For each number of decks I've calculated the number of occurences of that hand, and the cardinal ranking of their strengths.
|Five of a kind||13||1st||78||2nd||273||2nd||728||2nd||56,784||3rd||2,617,888||3rd|
|Four of a Kind||624||2nd||3,900||3rd||14,040||4th||38,220||4th||87,360||4th||4,542,720||4th||179,512,320||4th|
|Three of a kind||7,722||5th||54,912||6th||214,500||7th||617,760||7th||1,471,470||7th||3,075,072||7th||123,002,880||7th||4,357,816,320||7th|
Here are some takeaways:
When there is only one suit, all hands are either flushes or straight flushes! The straight flush is the rarest.
When a deck contains two suits, it's not possible to make four of a kind, three of a kind, or a full house. The straight flush is still the rarest hand, but a straight is less likely than a flush.
With three suits, all the standard poker hands are possible except four of a kind, but again the ranking of the flush and the straight are reversed.
With four suits, this is our vanilla deck, and the numbers correspond to those calculated earlier.
If we add a fifth suit, five of a kind is possible. This becomes the rarest hand, and the flush and the full house switch places.
With six suits (and beyond), five of a kind relinquishes the position of ranking highest, and this honour returns to the straight flush.
The rankings don't change from six to seven suits.
Nor do they change from seven to eight.
Things don't change again until 10 suits (not shown), when now it becomes more likely to have a pair than just a high card.
By 13 suits (not shown), the flush becomes the second ranking hand.
After 16 suits, the full house changes from fifth ranking to sixth ranking.
The rankings don't change from this point onwards.
What happens if we keep a deck with the standard four suits, but adjust the number of cards in every suit away from the standard 13?
The top table below shows decks with a range of cards up to a standard 13 card per suite deck.
|Five of a kind|
|Four of a Kind||8||1st||24||1st||48||1st||80||2nd||120||3rd||168||3rd||224||3rd||288||2nd||360||2nd||440||2nd||528||2nd||624||2nd|
|Three of a kind||192||3rd||768||3rd||1,920||5th||3,840||7th||6,720||6th||10,752||6th||16,128||6th||23,040||6th||31,680||6th||42,240||6th||54,912||6th|
The lower table shows larger decks.
|Five of a kind|
|Four of a Kind||624||2nd||728||2nd||840||2nd||960||2nd||3,968||2nd||261,120||3rd||67,092,480||3rd|
|Three of a kind||54,912||6th||69,888||6th||87,360||6th||107,520||6th||952,320||6th||530,595,840||5th||2,197,412,904,960||5th|
Here are some takeaways:
As there are only four suits it's always going to be impossible to make five of a kind.
Because there are only four suits, if we only have one distinct value for each card, there will be only four cards in the deck, so there is no way to make a five card hand! We need a minimum of two cards per suit to play poker.
With two numbers for each suit, in your five card hand, you either have four of a kind, or a full house.
With three values in each suit it's also possible to have three of a kind, or two pairs.
With four values in each suit it's possible to only have a pair for the first time.
Once we have five, or more, cards it's possible be able to make straights and straight flushes.
With five values, it's still not possible to just get a high card, as any five distinct cards in a set of five will always make a straight. Because of this, even though with five cards you can now make a flush, this will be a straight flush because they will be connected.
With six cards, both a straight flush and non-straight flush are equally likely. It's also possible to get a high card only for the first time.
With a small number of values, it's much more likely to get a pair than a high card. As the number of cards increases, this changes (changing over at 12).
With large numbers of cards per suit, high cards dominate. Flushes are also common.
If you are bored one afternoon, it might be a fun exercise to dust off a little code to see the sensitivity impact of losing one card in a deck. If you have a deck of cards and your kids have lost one (or the dog has eaten it), how does this change the odds for poker hands? If you know what the missing card is, how does this impact the rankings?
If you want to know how the odds change with the additional of wild cards, see my next article.