0
$\begingroup$

So I wanted to write a Python program to calculate some probabilities using hyper geometric distributions. However, I seem to get probabilities over 1 sometimes, so there must be something wrong with the mathematics behind the code.

Lets say I want to find out the probability of drawing exactly 1 King and exactly 2 Clubs (no more and no less) in a hand of 3 cards using a standard deck of cards (52 cards, 4 suits, 13 ranks). I have calculated the number of possible hands with these restrictions like this:

First, I calculated all possible ways of achieving such a hand, containing the King of Clubs. For that to happen, the hand must contain:

  • The King of Clubs: $1$ (K♣)
  • Another Club: $13-1 = 12$ (13 Clubs minus the King)
  • A card that is neither a Club not a King: $3*(13-1) = 36$ (3 suits that are not Club times 13 ranks minus the King)

Multiply them all together and you get $1*12*(3*(13-1)) = 432$.
To construct a valid hand without the King of Clubs you need:

  • A non-King Club: $13-1=12$ (13 Clubs minus the King)
  • A different non-King Club: $13-1-1=11$(13 Clubs minus the King and the previous Club)
  • A card that is not a Club but a King: $4-1=3$ (4 Kings minus the King of Clubs)

The number of possible hands are $12*11*3=396$.
As André Nicolas explained, this line would over count the amount of hands, as the number of ways to have the two non-King Clubs is not $12*11$, as the order doesn't matter. Thus, this should be $\binom{12}{2}*3$, which gives the right result, thanks, André!

Those added together makes a total amount of $432+396=828$ possible hands of three cards containing 1 King and 2 Clubs.

But thats unfortunately not it. As I tried to verify my example using Wolfram Alpha, I got a different answer: http://www.wolframalpha.com/input/?i=1+king+2+club+in+3+cards
As much as I tried, I found myself unable to replicate that result of Wolfram Alpha's, $630$. I thought, maybe I over counted some hands. Though it may not have been the most efficient method, I actually wrote another Python program to generate all possible hands. It then removed all hands that do not fit the description of having exactly 1 King and 2 Clubs in it. Also I checked for any duplicates inside that list. len(result)? $828$. I'm pretty sure, that $828$ is the right answer, but where does Wolfram Alpha get that $630$ from? Am I wrong after all? Also: How can you represent that task using sets and Venn diagrams?

$\endgroup$
  • $\begingroup$ "A non-King club": take the three of clubs. "A different non-King club": take the seven of clubs. "A non-King club": take the seven of clubs. "A different non-King club": take the three of clubs. $\endgroup$ – Daniel Fischer Sep 7 '14 at 13:53
  • $\begingroup$ For the hands with a non-club King and $2$ clubs, the King can be chosen in $3$ ways and for each way the $2$ clubs can be chosen in $\binom{12}{2}$ ways. Or else we can deliberately double-count and then divide by $2$. $\endgroup$ – André Nicolas Sep 7 '14 at 14:15
0
$\begingroup$

Wolfram Alpha is probably using a calculation like $1 \times 12 \times 36 + \frac{12\times 11}{2}\times 3 = 432+198 = 630$. Your 2nd calculation puts an implicit order on the two non-king clubs but not on the king non-club.

If you want the number of ways taking into account the order the cards appear (a sensible approach when calculating probabilities with replacement, and not much extra work without replacement), then it is either $6\times432+6\times 198$ or $6\times432+3\times 396$, either of which give $3780$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.