What is the probability that the third largest value of 39 rolls with a 9-sided dice is 8? If I have 39d9, that is 39 rolls with a 9-sided (fair) dice, what is the probability that the third-largest value of all the rolls is an 8? 
I know there are some specific situations where this is true, precisely if the three highest results are one of the following combinations: 888, 889 or 899.
If in the 39 rolls there are at least three 8s and no 9s, at least two 8s and precisely one 9, or at least one eight and precisely two 9s. 
I cannot seem to come up with a counting or probabilistic method for solving the problem. Can anyone help?
 A: Let's call $X_1, ... X_{39}$ the $39$ random variables corresponding to the $39$ rolls of the dice, and let's call $X_{(1)}, ..., X_{(39)}$ these random variables sorted from biggest ($X_{(1)}$) to smallest ($X_{(39)}$). 
I guess you want to compute $P(X_{(3)} = 8)$, which is
$P(X_{(3)} = 8) = P(X_{(3)} \geq 8) - P(X_{(3)} = 9)$
The event $"X_{(3)} = 9"$ happens if at least $3$ values are equal to 9, so, using a binomial distribution and the complementary event, its probability is $$P(X_{(3)} = 9) = 1 - (8/9)^{39} - 39\cdot1/9\cdot(8/9)^{38} - 39\cdot 19\cdot (1/9)^2\cdot(8/9)^{37}$$
The event $"X_{(3)} \geq 8"$ happens if at least 3 values are bigger than 8. So, using once again a binomial distribution and the complementary event, its probability is :
$$P(X_{(3)} \geq 8) = 1 - (7/9)^{39} - 39\cdot (2/9)\cdot (7/9)^{38} - 39 \cdot 19 (2/9)^2\cdot(7/9)^{37}$$
So you get that 
$$P(X_{(3)} = 8) = (8/9)^{39} - (7/9)^{39} - 39 \cdot [(1/9)(8/9)^{38} - (2/9)(7/9)^{37}] - 19\cdot39\cdot[(1/9)^2(8/9)^{37} - (2/9)^2(7/9)^{37}] \approx 0.173$$ 
Maybe this expression can be simplified a bit. 
A: Let's break down the possible outcomes:


*

*All dice rolls are 7 or below (i.e. 3rd largest is 7 or below).

*At least 3 dice rolls are 9 (i.e. 3rd largest is 9).

*Exactly one or exactly two dice rolls are 9, and the other are 7 or below.

*Your desired output (i.e. 3rd largest is exactly 8).


So, you can calculate the probabilities for the first three outcomes, take their sum, and subtract it from 1 to find the desired output.
The first one is easy to calculate - it's just $p_1 = ({7 \over 9})^{39} $
The second one is also not hard to calculate: The probability for $k$ successes in $n$ trials, with a probabilty $p$ to succeed, is $ \binom n k p^k(1-p)^{n-k} $. So, three or more "successes" (i.e. $9$'s) is the sum of that formula from $k=3$ to $k=39$ (with $n=39$ and $p={1 \over 9}$).
But since the sum from $k=0$ to $k=n$ is 1, it's easier to calculate  $$ p_2 = \sum_ {k=3}^{k=n} \binom n k p^k(1-p)^{n-k} = 1- \sum_ {k=0}^{k=2} \binom n k p^k(1-p)^{n-k} $$
For the third term, we again use the probabilities for exactly 1 or exactly 2 $9$'s, but each of those probabilities is multiplied by the probability that all others are $7$ or below, eventually giving:
$$ p_3 = n {1 \over 9} ({7 \over 9})^{39-1} + \binom n 2 ({1 \over 9})^2({7/9})^{39-2} $$
Your desired output is just $1-p_1-p_2-p_3$
