Probability of matching 5 cards from a deck of 40 Suppose we have a deck of 40 cards which has, 5 Aces, 6 Kings, 9 Queens, 20 Jacks. A game is played where a contestant will continuously draw cards until they have 5 matching cards (not necessarily in order). The cards are drawn without replacement.
I'm trying to find the probability of the contestant getting the five matching cards they get are all Aces (i.e. they have to get this before they get any other five matching cards).
Does anyone have any idea on how to approach this?
 A: Suppose a win occurs when the fifth ace is drawn on draw $r+1$, for $0 \le r \le 16$.  On the previous draw, the hand must have contained four aces and no more than four of any of the other ranks, and then the contestant must draw an ace on draw $r+1$.
Let's try to find the probability of being in a favorable state on draw $r$.  There are $\binom{40}{r}$ possible hands of $r$ cards, all of which we assume are equally likely.  We would like to count the number of hands containing exactly four aces and no more than four of any other rank, which we will call a "favorable hand".  To do this, we will find the generating function of the number of favorable hands.  Numbering the ranks from ace to jack as $1$ through $4$, let's say $n_i$ is the initial number of cards in the deck of rank $i$, for $i=1,2,3,4$, so $n_1 = 5$, $n_2=6$, etc.  If we consider only cards of rank $i$, then the generating function for the number of hands containing zero to four of those cards is 
$$\sum_{j=0}^4 \binom{n_i}{j} x^j$$
The generating function for the number of ways to draw exactly four aces is simply $\binom{5}{4}x^4$;  so the generating function for the number of favorable hands containing cards of all ranks is
$$f(x) = \binom{5}{4}x^4 \prod_{i=2}^4 \sum_{j=0}^4 \binom{n_i}{j} x^j$$
I.e., the coefficient of $x^r$ when $f(x)$ is expanded, which which we will denote by $[x^r]f(x)$, is the number of hands containing exactly four aces and no more than four of any other rank.  After some computation (I used Mathematica, but a pencil and paper computation should not be difficult),
$$f(x) = 5 x^4+175 x^5+2975 x^6+32725 x^7+261800 x^8+ \\ 
1544980 x^9+6741525 x^{10}+21960225
   x^{11}+53723775 x^{12}+ \\ 96756975 x^{13}+122906250 x^{14}  +102343500
   x^{15}+45785250 x^{16}$$
The probability of a favorable hand of $r$ cards is then 
$$\frac{[x^r]f(x)}{\binom{40}{r}}$$
In order to win on draw $r+1$ the player must have a favorable hand on draw $r$ and then draw an ace on draw $r+1$, when there is one ace left in the deck and $40-r$ cards total.  So the probability of a win on draw $r+1$ is 
$$\frac{[x^r]f(x)}{\binom{40}{r}} \cdot \frac{1}{40-r}$$
and the overall probability of winning is
$$\sum_{r=0}^{16} \frac{[x^r]f(x)}{\binom{40}{r}} \cdot \frac{1}{40-r} = \boxed{0.00194347}$$
Edit (deleted)
Edit to the Edit
Prompted by one of the comments, I provided a list of learning resources for people who are new to generating functions and would like to learn about them.  I have moved that list to a new question and answer here because it seems more suitable for development as a community resource.  Please take a look.
