From charlesreid1

Line 150: Line 150:
Then we can exclude the hands with a royal flush, since we already counted them in the royal flush outcomes above.
Then we can exclude the hands with a royal flush, since we already counted them in the royal flush outcomes above.


The procedure for a straight flush is similar to the procedure for a royal flush: we begin by selecting a suit, which is <math>\binom{4}{1}</math>, then we go on down the line and select our cards. If a straight consists of 5 cards, the straight must start with a card between 2 and 10. If the straight starts with 10, it is a royal flush and we have already counted it. Therefore, the first card in the straight flush can be any one of the cards 2 through 9. That's (9-2+1) = 8 total choices of cards.
The procedure for a straight flush is similar to the procedure for a royal flush: we begin by selecting a suit, which is <math>\binom{4}{1}</math>, then we go on down the line and select our cards. If a straight consists of 5 cards, the straight must start with a card between 2 and 10. If the straight starts with 10, it is a royal flush and we have already counted it. Therefore, the first card in the straight flush can be any one of the cards A through 9. That's 9 total choices of cards.


Once we select a suit and a starting card, the rest of the cards are determined - each remaining position in the hand has only one card that can fill it.
Once we select a suit and a starting card, the rest of the cards are determined - each remaining position in the hand has only one card that can fill it.


Therefore the probability of having a straight flush in one's hand is:
Therefore the count of straight flush hands is:


<math>
<math>
P_{\mbox{royal or non-royal straight flush}} = \binom{4}{1} \times 8 = \dfrac{2}{162,435} \approx 0.000012312...
C_{\mbox{straight flush}} = 7 \binom{4}{1}
</math>
</math>


of which precisely 4 outcomes area already accounted for (as royal flushes), giving:
and the probability of having a straight flush in one's hand (not counting royal flushes) is:


<math>
<math>
P_{\mbox{straight flush}} = \left( \binom{4}{1} \times 8 - \binom{4}{1} \right) = \dfrac{1}{92,820} \approx 0.000010774...
P_{\mbox{straight flush}} = \dfrac{ 7 \binom{4}{1} }{ \binom{52}{5} }
</math>
</math>



Revision as of 01:13, 24 July 2017

Mathematics related to cards.

Combinatorics and Counting

Probability of 5-Card Hands

Here, we give two examples that illustrate the care that is needed when setting up the problem and deciding how to model the process. In the first procedure, we are looking for five-card hands with at least one particular face value - which we model as a single event. In the second procedure, we are looking for five-card hands with exactly one occurrence of a particular face value, which requires us to think about each card being dealt as separate events.

Note that the total number of 5-card hands is given by $ \binom{52}{5} = 2,598,960 $.

Hand with at least one X

Suppose we wish to know the probability that a given 5-card hand will contain at least once ace.

In this case, it is slightly easier to enumerate the number of hands that do not contain any aces. We re-pose the problem as counting the number of ways we can form 5-card hands from 48 cards (the 52 total minus the 4 aces). This probability is given by:

$ \binom{48}{5} = 1,712,304 $

This gives the total number of 5-card hands that contain at least one ace as the total number of possible hands minus the number of hands without aces:

$ \binom{52}{5} - \binom{48}{5} = 886, 656 $

If we want a probability, we can compute the number of hands with aces over the number of total hands:

$ \dfrac{\binom{52}{5} - \binom{48}{5}}{\binom{52}{5}} = \dfrac{18,472}{54,145} \approx 0.3411\dots $

We can empirically verify this by writing up a simple computer program: it creates a deck of cards, shuffles it, picks 5 cards at random, and determines if there is an ace in the hand. It repeats this procedure millions of times. Here are the results of several runs of the program, showing good agreement with theory:

$ javac CountAces.java && java CountAces
N_aces / N_cards = 341129 / 1000000 = 0.3411
N_aces / N_cards = 341178 / 1000000 = 0.3412
N_aces / N_cards = 341416 / 1000000 = 0.3414

Now, you may be wondering why we use the binomial distribution, if we are trying to model a process with replacement? Isn't the hypergeometric distribution more appropriate? (Maybe not after seeing the numbers presented above.) Well, you would almost be correct - except for the fact that we are only analyzing a single event, so it doesn't matter whether we replace or not.

In other words, in this process, success is not defined as "the next card being dealt comes up an ace", with many trials and many outcomes. Success is defined as "one of five cards, pulled at random from the deck, will be an ace." That means that pulling five cards is a single event, a single independent trial, with a single outcome. The program above shuffles the deck between each hand, so each hand is a single, independent trial.

Another way to think about it is, our success criteria applies to all of the cards at once, and is only met or not when all five cards have been dealt.

We will see in the next section that if we are concerned with the actual process of dealing the hand (i.e., we check criteria as the deal is happening), then we must treat each card as a separate event - and then we no longer have independent sampling with replacement, and we cannot use the binomial distribution. Instead, we have sampling without replacement, and we must use the hypergeometric distribution.

Hand with exactly one X

Now suppose we wish to know the probability that a given 5-card hand contains exactly one ace. We must exclude some of the solutions above that contain multiple aces.

To do this, we need to treat each card as a separate event, and analyze the outcomes of each event to rule certain outcomes out. Each card is removed without replacement, so the distribution that we see for each card changes slightly. We deal with this by using a hypergeometric distribution.

We begin by defining the following parameters:

  • K = number of possible success events = 4 aces in deck
  • k = number of success events we want = 1 ace
  • N = size of population being sampled = 52 cards
  • n = size of sample = 5 cards

Then the number of outcomes with exactly k successes in n trials will be given by:

$ \mbox{Outcomes with k successes} = \binom{K}{k} \binom{N-K}{n-k} = \binom{4}{1} \binom{48}{4} = 778,320 $

The probability divides outcomes with k successes by total number of outcomes:

$ P_{1ace} = \dfrac{ \binom{K}{k} \binom{N-K}{n-k} }{ \binom{N}{n} } = \dfrac{ \binom{4}{1} \binom{48}{4} }{ \binom{52}{5} } = \dfrac{778,320}{2,598,960} \approx 0.2994... $

(Note that there are other forms of this equation, but I find the form given above is the easiest to remember.)

If we were to change our requirement to hands with exactly two aces, our probability decreases to:

$ P_{2aces} = \dfrac{ \binom{K}{k} \binom{N-K}{n-k} }{ \binom{N}{n} } = \dfrac{ \binom{4}{2} \binom{48}{3} }{ \binom{52}{5} } = \dfrac{103,776}{2,598,960} \approx 0.0399... $

I followed up on this by modifying the card-shuffling program written above to count number of hands containing exactly 1 ace, and then exactly 2 aces. Here is some output from that program:

$ javac CountAces.java && java CountAces
N_aces / N_cards = 340906 / 1000000 = 0.3409
N_aces / N_cards = 341865 / 1000000 = 0.3419
N_aces / N_cards = 340290 / 1000000 = 0.3403
N_twoaces / N_cards = 39990 / 1000000 = 0.0400
N_twoaces / N_cards = 40175 / 1000000 = 0.0402
N_twoaces / N_cards = 39872 / 1000000 = 0.0399

This lists the number of hands with exactly two aces, out of a million trials, along with the corresponding probabilities.

Table of Poker Hand Probabilities

Consider the list of outcomes from a 5-card poker hand:

  • High Card: Highest value card.
  • One Pair: Two cards of the same value.
  • Two Pairs: Two different pairs.
  • Three of a Kind: Three cards of the same value.
  • Straight: All cards are consecutive values.
  • Flush: All cards of the same suit.
  • Full House: Three of a kind and a pair.
  • Four of a Kind: Four cards of the same value.
  • Straight Flush: All cards are consecutive values of same suit.
  • Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.

We will demonstrate computation of probabilities of the occurrence of each hand in 5 random cards being drawn.

Calculating Probabilities

Note that even with a simple calculation, like how many one-pair hands are possible, gets tricky - some of the one-pair hands will result in three of a kind, some will result in a full house, some will result in two pair, and some will result in a flush.

To do the calculation, we really need to be able to say:

(Number of hands with exactly one-pair) = (Number of hands with at least one pair) - (Number of hands with 3 of a kind) - (Number of hands with full house) - (Number of hands with flush)

Therefore, we start by counting the number of outcomes of the rarest occurrences, and work our way backwards, which allows us to apply the principle of Inclusion-Exclusion to account for the duplicates.

Royal Flush

A royal flush is a 10, J, Q, K, A of the same suit. There are only 4 royal flushes possible (4 suits).

Letting C denote the COUNT of poker hands with this outcome, and P denote the PROBABILITY of a poker hand with this outcome, we have:

$ C_{\mbox{royal flush}} = \binom{4}{1} \cdot 1 \cdot 1 \cdot 1 \cdot 1 = 4 $

We construct this number by first selecting one suit from among 4 - that's $ \binom{4}{1} $ - and once we do that, we have exactly one of each type of remaining card that we can select.

We can either think of the choice of suit as an independent choice, whereupon each position ion the hand has exactly 1 card that works, or we can think of it as choosing from among the 4 Aces, and that choice then determines the suit of the remaining cards. Etc.

Therefore the probability of a royal flush is

$ P_{\mbox{royal flush}} = \dfrac{ \binom{4}{1} }{ \binom{52}{5} } = \dfrac{1}{649,740} \approx 0.0000015391 \approx 1.5391 \times 10^{-6} $

Straight Flush

A straight flush contains cards of consecutive values, all of the same suit.

Using the principle of inclusion-exclusion, we can write the number of hands with a straight flush outcome as:

(Hands with straight flush) = (Hands with royal flush) + (Hands without royal flush)

Then we can exclude the hands with a royal flush, since we already counted them in the royal flush outcomes above.

The procedure for a straight flush is similar to the procedure for a royal flush: we begin by selecting a suit, which is $ \binom{4}{1} $, then we go on down the line and select our cards. If a straight consists of 5 cards, the straight must start with a card between 2 and 10. If the straight starts with 10, it is a royal flush and we have already counted it. Therefore, the first card in the straight flush can be any one of the cards A through 9. That's 9 total choices of cards.

Once we select a suit and a starting card, the rest of the cards are determined - each remaining position in the hand has only one card that can fill it.

Therefore the count of straight flush hands is:

$ C_{\mbox{straight flush}} = 7 \binom{4}{1} $

and the probability of having a straight flush in one's hand (not counting royal flushes) is:

$ P_{\mbox{straight flush}} = \dfrac{ 7 \binom{4}{1} }{ \binom{52}{5} } $

Combinatoric Solitaire

Knuth mentions an anecdote about runs/sequences of increasing integers - there was a mathematician/scientist who would play a form of solitaire in which he would place cards on an existing pile as their face value increased, and start a new pile as their face values decreased. The question is, how many piles will result, and playing this form of solitaire is a form of "empirical" sampling.

Related