Counting poker hands

In this morning’s blog post, John D. Cook talks about poker hands and their probabilities. In particular, he says

For a five-card hand, the probabilities of 0, 1, or 2 pair are 0.5012, 0.4226, and 0.0475 respectively.

Upon reading this, I assumed there’d be an explanation of how these probabilities were calculated. But no, he just leaves us hanging. So I sat down and worked them out.

The probabilities are going to be calculated by dividing the number of ways we can get a certain type of hand by the total number of possible hands. So let’s start by working out the denominator. There are 52 cards, so if we deal out 5 cards, there are

(525)=2,598,960

possible ways to do it. The symbol that looks sort of like a fraction without the dividing line represents the binomial coefficient,

(nk)=n!k!(nk)!

This is not only the coefficient of binomial expansions, it’s also the number of ways we can choose k items out of n without regard to order, also referred to as the number of combinations.

To figure out the number of one-pair hands, imagine the deck laid out in 13 piles: a pile of aces, a pile of kings, a pile of queens, and so on. We then do the following:

  1. Pick one of the piles. There are 13 ways to do this.
  2. From that pile, choose 2 cards. There are

    (42)=6

    ways to do this.

  3. Pick three other piles. There are

    (123)=220

    ways to do this.

  4. Pick one card from each of these three piles. Since there are 4 cards in each pile, there are 4 3=64 ways to do this.

So the total number of one-pair hands is

13×6×220×64=1,098,240

and the probability of getting a one-pair hand is

1,098,2402,598,960=0.42257

Moving on to two-pair hands, we start with the same 13 piles we had before. We then do the following:

  1. Pick two of the piles:

    (132)=78
  2. Pick two cards from each of these piles:

    (42)×(42)=6×6=36
  3. At this point, any of the remaining 44 cards will give us a two-pair hand.

Therefore, the total is

78×36×44=123,552

and the probability of drawing a two-pair hand is

123,5522,598,960=0.04754

Counting the number of no-pair hands is a little trickier because we have to make sure we don’t mistakenly count better hands, i.e., straights and flushes. Starting again with our 13 piles, we do the following:

  1. Pick 5 piles

    (135)=1,287
  2. Eliminate all the straights from this number. The number of straights is most easily done through simple enumeration:

    A–5, 2–6, 3–7, 4–8, 5–9, 6–10, 7–J, 8–Q, 9–K, 10–A

    So 10 of our 1,287 possible pile selections will give us a straight. That leaves 1,277 non-straight possibilities.

  3. Pick one card from each of the selected piles. That gives 4 5=1,024 possibilities.
  4. Eliminate the flushes from this set of possibilites. There are 4 flushes, leaving 1,020 possibilities.

These steps give us

1,277×1,020=1,302,540

hands that are worse than one-pair. The probability of getting such a hand is

1,302,5402,598,960=0.50118

I kept one more digit in my answers than John did, but they all match.