The Forge Reference Project

 

Topic: Calculating card-hand odds
Started by: clehrich
Started on: 2/20/2004
Board: RPG Theory


On 2/20/2004 at 3:18pm, clehrich wrote:
Calculating card-hand odds

Hey, math people,

Can you help me calculate some odds that use cards? The difficulty, of course, being that every card drawn changes the pack, thus each draw affects the odds on remaining cards. I keep getting stuck.

Let’s say we have 52 cards. (p=52, as in pack)
Now the odds of picking an ace off the top are 4/52, right?

Okay, so let’s say we have a hand of 5 cards (h=5)
What are the odds of drawing 1 ace in the hand? 2 aces? 3 aces? All 4 aces?

Now let’s make it more complicated. Let’s suppose Aces have one value (A), Kings another (K), Queens (Q), Jacks (J). So any 5-card hand can have a value ranging from 0 (no aces or face cards) to 4A+K (assuming Ace high and so on).

What’s the average value of the hand?

Can anyone express this as a formula, so I can make various such odds calculations myself?

Chris Lehrich

Message 9895#103601

Previous & subsequent topics...
...started by clehrich
...in which clehrich participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/20/2004




On 2/20/2004 at 4:04pm, james_west wrote:
Re: Calculating card-hand odds

The first question includes probability and combinatorial analysis:

The number of combinations of n objects taken r at a time -
C(n,r) = n!/r!(n-r)!

How many ways are there of choosing five cards out of 52?

C(52,5)=5!/52!(52-5)!=2,598,960 possible hands.

There is only 1 way of drawing all 4 aces, but 48 other possible cards that could be drawn for the fifth card, so there are 48 hands that include all 4 aces.

The odds of drawing 4 aces are thus 48/2,598,960 = 1 in 54,145

The number of ways of drawing -no- ace is
C(48,5)=5!/48!(48-5)!= 1,712,304

So the probability of drawing no ace is 1,712,304/2,598,960 =
about 66% (so the probability of drawing at least one ace is one minus this).

As a few more examples:

The probability of drawing exactly two aces is

C(4,2)*C(48,3)/C(52,5) = 3.99% [fixed after Walt pointed out a multiplication error]

The probability of drawing three spades and two hearts is

C(13,3)*C(13,2)/C(52,5) = 0.9%

The probability of drawing four black cards and one red is

C(26,4)*C(26,1)/C(52,5) = 15%


- Does that make sense ?

James [edited to correct a multiplication error]

Message 9895#103609

Previous & subsequent topics...
...started by james_west
...in which james_west participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/20/2004




On 2/20/2004 at 4:31pm, james_west wrote:
RE: Re: Calculating card-hand odds

clehrich wrote: Aces have one value (A), Kings another (K), Queens (Q), Jacks (J). So any 5-card hand can have a value ranging from 0 (no aces or face cards) to 4A+K (assuming Ace high and so on).


What is the probability of drawing no face cards?

52 cards includes 16 face cards or aces, thus 36 that are not

C(36,5)= 376,992

So odds of drawing no face cards are only about 15%

Prob of 1 card:
C(36,4)C(16,1)/C(52,5) = 36%

Prob of 2 cards:
C(36,3)C(16,2)/C(52,5)= 33%

Prob of 3 cards:
C(36,2)C(16,3)/C(52,5)=13%

Prob of 4 cards:
C(36,1)C(16,4)/C(52,5)=2%

Prob of 5 cards:
C(16,5)/C(52,5)=0.2%

Message 9895#103616

Previous & subsequent topics...
...started by james_west
...in which james_west participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/20/2004




On 2/20/2004 at 5:10pm, Walt Freitag wrote:
RE: Calculating card-hand odds

Odds of drawing one ace off the top are indeed 4/52.

If we look at it step by step the odds of drawing one (and only one) ace in a five-card hand are:
4/52 * 48/51 * 47/50 * 46/49 * 45/48 <-- ace drawn first
+ 48/52 * 4/51 * 47/50 * 46/49 * 45/48 <-- ace is second card drawn
+ 48/52 * 47/51 * 4/50 * 46/49 * 45/48 <-- etc.
+ 48/52 * 47/51 * 46/50 * 4/49 * 45/48
+ 48/52 * 47/51 * 46/50 * 45/49 * 4/48

Eachline turns out to be the same -- the numerator is always 52*51*50*48*47 and the denominator is always 48*47*46*45*4. This makes sense, the odds of drawing any given hand in any specific order is the same as the odds of drawing the same hand in a different specific order. So the odds reduce to

((4 * (48*47*46*45)) / (52*51*50*49*48)) * 5

What this really represents is

((number of ways to draw an ace * (number of ways to draw four non-ace cards)) / (total number of ways to draw five cards)) * the number of different ways the ace and the non-ace cards can be "mixed" in the hand.

For two aces, the calculation becomes:
(((4*3) * (48*47*46)) / (52*51*50*49*48)) * 10

It's easy to see why the 4 became 4*3, because we're now drawing two aces (first drawing from four possibilities, and then drawing from the three remaining possibilities). And it's easy to see why the 48*47*46*45 turned into 48*47*46, because we're only drawing three non-ace cards instead of four. But where did the 10 come from? Did I multiply it by 2 because we're drawing 2 aces instead of one?

No, it's not quite that simple. The 10 represents the number of different ways in which the drawing of the aces could mix with the drawing of the non-ace cards. There are ten different ways that can happen:

AAxxx
AxAxx
AxxAx
AxxxA
xAAxx
xAxAx
xAxxA
xxAAx
xxAxA
xxxAA

Let's move on. For three aces in a five-card hand we've got:

(((4*3*2) * (48*47)) / (52*51*50*49*48)) * 10

All the terms have changed again in the same pattern, except that the 10 stayed the same. But it should be no surprise that the number of different possible sequences for drawing three aces and two non-ace cards is the same as the number of different sequences for drawing two aces and three non-ace cards. If you want to list them all, just reverse the xs and the As in the list above.

Finally, for drawing all four aces, the odds are:
(((4*3*2*1) * 48) / (52*51*50*49*48)) * 5

You can easily modify this for larger hands, different size decks, and so forth. But things get complicated when the description of the target hand gets more complicated. For example, suppose I had a standard 52-card deck, and I want to know the odds of drawing a five-card full house (a three of a kind, a pair, and some other card). I'd calculate it this way:

((52*3*2) * (48*3) * 44) / (52*51*50*49*48*47)) * 10 * 6

(As is also true above, most of the parentheses are irrelevant to the actual calculation, they're just there to group the factors together conceptually.)

The 52*3*2 represents the three matching cards of the full house (any card, then one of the three remaining cards matching it, then one of the two remaining cards matching it). The 48*3 similarly represents the other two cards in the full house (any of the 48 cards not matching the three of a kind, then one of the 3 cards matching that card). The 44 represents any of the remaining cards in the deck that don't match the three of a kind or the pair.

The denominator, as before, represents the total number of ways of drawing six cards. (Note that this is not the same as the number of distinct six-card hands that can be drawn, because we're taking the order the cards are drawn into account.)

The factor of 10 is the number of ways the cards of the pair and the cards of the three of a kind might mix in sequence as the cards are drawn. (Mixing two out of 5, just as when drawing two aces in a five-card hand as above.) The separate factor of 6 represents the six possible positions that the sixth waste card might appear.

I find that reasoning about probabilities this way works better for me than trying to use canned formulas, because the formulas hardly ever are for exactly what I want to calculate, and it's hard to modify a formula without understanding how it's constructed and what the different parts of it actually represent -- which usually means I have to re-derive the formula for myself from basic principles anyhow.

Figuring out the number of ways some number of items might be mixed into a larger number of items can be the sticking point. If you want to know how many ways the heads and the tails might be sequenced when 2 heads total are flipped in 5 coin flips, the answer is 10 (same as the number of ways aces and non-aces can be sequenced when drawing 2 aces in a five-card hand). But what if you want to know the number of ways 5 heads might be flipped out of 10 flips? The answer is 252, which means it's not very convenient to determine this by listing them all. Instead, you use the binomial coefficient function:

binomial(n, r) = n! / (n-r)!r!

where n is the number of coin flips, cards, etc. you're doing and r is the number of them that have the distinction you're looking for -- e.g. are aces or heads. (The function, equivalently, tells you the number of different sets you can get by choosing r objects from a set with n distinct elements.)

When actually calculating binomial coefficients, either by hand or by computer program, it's not a good idea to actually calculate the n! and (n-r)! separately and then divide them. By hand it's a lot of usually unnecessary work, and by computer it's easy to overflow numbers (especially of integer types) with the factorial function. It's more efficient to multiply out n * n-1 * n-2 * ... and stop after ...*(n = r+1). Consider that if n is 52 and r is 47, n!/(n-r)! is just 52*51*50*49*48 without having to divide two huge numbers.

By hand, you can also get binomial coefficients from Pascal's Triangle.

----------

As for the average value problem, let's see. Averages can be relatively easy to calculate because they usually allow for some shortcuts. In this case, I don't have to e.g. figure out how many possible hands have two queens and a jack, and so forth. Instead:

There are n = 52*51*50*48*47/120 possible different 5-card hands from a 52-card deck. (This time I don't care about what order the cards were drawn in, which is why the division by 120; every 5-card hand can be drawn in 120 different sequences). Those hands have a total of n*5 cards in them, and each specific card appears equally often. So for instance one of every 52 of those n*5 cards is the ace of spades. Four of every 52 are an ace of some kind.

Altogether, then, aces appear n*5*4/52 times in our n hands, and so do kings, queens, and jacks. So the average number of aces per hand is n*5*4/52 divided by n. The n's cancel out, so the average number of aces per hand is 20/52 (=5/13). That's also the average number each of kings, queens, and jacks. The average value of a hand is therefore 5(A + K + Q + J)/13.

You might have guessed that to begin with, and then worried that the answer shouldn't be that simple because e.g. once you draw one ace in your hand the odds of drawing a second one are reduced. Turns out that doesn't matter in figuring the average.

- Walt

Message 9895#103624

Previous & subsequent topics...
...started by Walt Freitag
...in which Walt Freitag participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/20/2004




On 2/20/2004 at 5:20pm, james_west wrote:
RE: Calculating card-hand odds

Walt - looks like we're doing the same thing. You've probably done a better job of explaining the origin of the formula (I started into that, and it got messy, so I stopped ...)

- James

Message 9895#103627

Previous & subsequent topics...
...started by james_west
...in which james_west participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/20/2004




On 2/20/2004 at 5:32pm, Walt Freitag wrote:
RE: Calculating card-hand odds

Yes, it amounts to the same thing. (I was worried because I got a different result of 3.99% for drawing two aces, but I think you just had a calculating glitch, because I get 3.99% for C(4, 2) * C(48,3) / C(52, 5) too.) My post crossed yours, but perhaps having it expressed two different ways will be helpful.

- Walt

Message 9895#103632

Previous & subsequent topics...
...started by Walt Freitag
...in which Walt Freitag participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/20/2004




On 2/21/2004 at 4:03am, clehrich wrote:
RE: Calculating card-hand odds

Although I admit that my first response to you guys comes from The Fly -- "eeelp meeee!" -- I think that between both I can probably work it out reasonably. Thanks, guys!

Chris Lehrich

P.S. Now if we suppose that one of the cards actually negates the value of another, such that ...... :->

Message 9895#103724

Previous & subsequent topics...
...started by clehrich
...in which clehrich participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/21/2004




On 2/21/2004 at 4:59am, M. J. Young wrote:
RE: Calculating card-hand odds

I thought I would throw in (in case it was overlooked) that this all changes if

• You have more than one hand

and

• Hands are dealt open.


That is, obviously, if you're dealing two hands by alternating between two players, then the number of cards in the deck for each card dealt to the first goes from fifty-two to fifty to forty-eight (not one card per step). Clearly the no player can be dealt a card that has already been dealt to another player--the odds of that happening are zero. However, from the perspective of any one player, if the cards already dealt to the other players are not known, they remain statistically part of the deck for purposes of calculation. However, in games like Blackjack where at least some of the cards previously dealt are visible, these, too, have to be factored into the odds for the next card on the deck.

--M. J. Young

Message 9895#103732

Previous & subsequent topics...
...started by M. J. Young
...in which M. J. Young participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/21/2004




On 2/21/2004 at 1:04pm, HMT wrote:
RE: Calculating card-hand odds

This is a question of when the probabilities are being calculated. The order in which cards are dealt and your ability or lack of ability to see the other players cards has no effect on the probability of getting a particular hand as calculated before the hands are dealt.

This extra information is no different than the information gained by knowing part of a hand. For example, the probability of a randomly dealt five card hand containing three aces does not depend on whether other hands are dealt or whether hands are dealt open or closed. The question of whether a randomly dealt five card hand that contains the eight of hearts also contains two aces is a different question.

Message 9895#103766

Previous & subsequent topics...
...started by HMT
...in which HMT participated
...in RPG Theory
...including keyword:

 (leave blank for none)
...from around 2/21/2004