Tuesday, April 13, 2010

On poker hand probabilities

Ever since I learned how to do it back in Year 12 Applicable Maths, I seem to keep coming back every once in a while to re-calculate the probabilities of the different poker hands. A big part of this is that I keep forgetting which is the better hand between a straight and a flush. I've never played enough poker to have this cemented in my mind by sheer experience, so I'm always hoping that by going through the calculation one more time, I'll develop some kind of solid intuition.

That hasn't really worked so far, but at least this time round I can record it in this here blog for posterity...

So, we begin with a standard deck of cards, 52 cards arranged into 4 suits and 13 ranks. The first thing to decide is how many distinct poker hands are there? Adopting standard mathemathical notation, the answer is 52_C_5, pronounced "52 choose 5". This "choose" function pops up all over the place when calculating poker hand probabilities; it is calculated by doing (52 x 51 x 50 x 49 x 48) / (5 x 4 x 3 x 2 x 1). Intuitively, the numerator represents the number of choices for each of the five cards: i.e. there are 52 choices for the first card, 51 for the second (since we've already removed one from the deck), and so on. But since the order doesn't matter, we need to divide by all the ways of re-arranging the 5 cards, which is what the denominator represents. The final answer is 2,598,960.

For the various poker hands, we will work out how many there are of each; the fewer there are, the more valuable the hand. The probability of being dealt a given type of hand will then be given by this number divided by the total number of hands just computed.

Now, the most valuable hand is the royal flush: 10JQKA, all of the same suit. It's pretty easy to see that there are only 4 such hands, one for each suit.

Next comes the straight flush. There are 4 suits, and for each suit there are 9 possible straights ranging from A2345 to 910JQK (we don't include 10JQKA since this is a royal flush). So there are 4 x 9 = 36 distinct straight flushes.

Now, four-of-a-kind. There are 13 different choices for the 4 cards. The extra card in the hand (which has no bearing on the hand's value) can be any of the remaing 48 cards. There are thus 13 x 48 = 624 ways to get a four-of-a-kind.

After that, we move into the realm of hands that you can expect to get more than once in a lifetime, beginning with the full house (three of one rank, two of another). There are 13 choices for the three-of-a-kind rank, and for each one, there are 4_C_3 = 4 ways to choose the suits of the three cards (more intuitively, you could say there are 4 choices for the suit not present). There are then 12 choices for the rank of the pair, and for each one 4_C_2 = 6 ways to choose their suits. So, there are 13 x 4 x 12 x 6 = 3744 ways to get a full house.

Now we reach the point where the flush and straight jostle uncertainly in my memory. Let's take a punt and tackle the flush first. A flush is five cards of the same suit, but which do not form a straight. The simplest way to calculate this is to calculate all flushes including straights, then subtract the number of straight flushes and royal flushes that we already calculated above. So, there are 4 suits for the flush and 13_C_5 choices for the ranks of the cards. From this we must subtract 36+4. We end up with 4 x 13_C_5 - 40 =  5108 ways to get a flush.

Arranging cards in order of rank (lowest to highest), there are 10 different straights from A2345 to 10JQKA -- ignoring the suits. Each card can be one of 4 different suits, so there are 10 x 4 x 4 x 4 x 4 x 4 = 10,240 possibilities. But once we need to subtract the 40 straight and royal flushes, so there are actually 10,240 - 40 = 10,200 ways to get a straight.

It's interesting to see that there are approximately actually twice as many ways to get a straight than a flush, and yet it's not intuitively clear (to me, at least) which should be the more likely.

Now that the order of flush and straight has been resolved, let's run quickly through the remaining, more prosaic, hands. 

Three-of-a-kind: 13 choices for the triplet, and 4_C_3 = 4 choices for their suits. The remaining two cards must have different ranks from the triplet and from each other (otherwise we'd get four-of-a-kind or a full house). There are 12_C_2 = 12 x 11 / 2 = 66 choices for their ranks, and 4 choices for each of their suits. Thus we have 13 x 4 x 66 x 4 x 4 = 54912 ways to get three-of-a-kind.

Two pair: 13_C_2 = 13 x 12 / 2 = 78 choices for the rank of the pairs, and for each one, 4_C_2 = 6 choices for their suits. The fifth card can be any of the remaining 44 cards. So there are 78 x 6 x 6 x 44 = 123,552 ways to get two pair.

Finally, the humble pair. There are 13 x 4_C_2 = 13 x 6 = 78 ways to get two cards of the same rank. The remaining cards must have different ranks from each other and from the pair (otherwise we'd have a more valuable hand). There are 12_C_3 = 220 choices for their ranks, and 4 choices for the suit of each one. There are thus 78 x 220 x 4 x 4 x 4 = 1,098,240 ways to get a pair.

What about the number of ways of getting nothing at all? Well, subtracting all the above from the total number of hands, we get 1,302,540, which is a probability of approximately 50.1%.

Poker hands --- Done!

No comments:

Post a Comment