# A six-sided die is rolled 5 times. The roller wins if the last roll is the same as one of the previous rolls.

What is the probability of winning this game?

I tried some but the closest I get was $\frac 16 \cdot \frac 16$, but it's not right.

• @ManojKumar wrong about what? – Hector Dec 8 '16 at 20:21
• There are several fine answers and there has been plenty of time for others to be posted. It might be time to pick one as the "accepted" answer. – David K Dec 17 '16 at 20:31

Write down the results of the five rolls and then read them backwards. You win if the "first" result is ever repeated, and you lose if it's not. The probability of losing is $(5/6)^4$ -- i.e., a given roll does not repeat the "first" result with probability $5/6$, and there are $4$ "subsequent" rolls -- so the probability of winning is

$$1-\left(5\over6\right)^4={1296-625\over1296}={671\over1296}$$

• It's useful to note that how you pick the winning number (the last roll) isn't relevant to the probability. This question reduces to "What is my chance of getting an x with four dice?". – bob2 Dec 8 '16 at 17:21

[This is essentially the same as Dominik's answer, but has less notation.]

Let the die have $n$ sides. Let $m$ be the number of rolls before the last roll. In your question $m=4$ and $n=6$. \begin{align} P(\text{win}) &= \sum_{i=1}^n P(\text{win, and last roll is $i$})\\ &= \sum_{i=1}^n P(\text{last roll is $i$, and one of the first $m$ rolls is $i$})\\ &= \sum_{i=1}^n P(\text{last roll is $i$}) \cdot P(\text{one of the first $m$ rolls is $i$})\\ &= \sum_{i=1}^n P(\text{last roll is $i$}) \cdot (1-P(\text{none of the first $m$ rolls is $i$}))\\ &= \sum_{i=1}^n \frac{1}{n} \cdot \left(1-\left(1 - \frac{1}{n}\right)^m\right)\\ &= 1-\left(1 - \frac{1}{n}\right)^m. \end{align}

Essentially, this question is the same as here. I will shamelessly adapt Byron's answer from there.

Assume we have a die with $n$ sides that we roll $m$ times before our final roll. Let $A_i$ be $1$ if we have rolled $i$ at some point and $0$ else. Also, denote by $X$ the last throw.

Now we will win if and only if the random variable $$Y = \sum \limits_{i = 1}^n A_i I\{X = i\}$$

has a value of one. Note that $Y$ only assumes values $0$ and $1$, so we have $E[Y] = P(Y = 1)$. Knowing that $X$ and $A_i$ are independent, it remains to calculate $$E[A_i] = P(A_i = 1) = 1 - P(A_i = 0).$$ But this is easy, since $P(A_i = 0) = (1 - \tfrac{1}{n})^m$. With this we can calculate the winning probability as $$E[Y] = \sum \limits_{i = 1}^n E[A_i] P(X = i) = (1 - (1 - \tfrac{1}{n})^m) \sum \limits_{i = 1}^n P(X = i) = 1 - (1 - \tfrac{1}{n})^m.$$

Side note: We can actually see in this calculations that $X$ doesn't even need to be a fair die, as long as it only assumes values from $1$ to $n$.

• "We can actually see in this calculations that $X$ doesn't even need to be a fair die ... ." I don't see it at all. In fact with $n=2,$ $m=1$, and the die being so unfair that one outcome has probability $2/3$, the other $1/3$, I get $E[Y]=5/9\neq1-(1-\frac1n)^m.$ – David K Dec 7 '16 at 22:55
• @DavidK I only mean $X$, which is the last thrown die. – Dominik Dec 7 '16 at 23:15
• I assumed "a die is rolled $m$ times" means the same die--but you're right, if die $X$ can be different from the others then it can be so unfair it rolls $1$ every time, and it makes no difference in the final result. – David K Dec 7 '16 at 23:18

For a die with $n$ sides and $m$ rolls we have $n^m$ possible outcomes and the favorable ones are given by

$$\sum_{q=1}^n q {n\choose q} {m-1\brace q} q! = n\sum_{q=1}^n {n-1\choose q-1} {m-1\brace q} q!.$$

What is happening here is that we choose $q$ values from the $n$ available ones (factor ${n\choose q}$) and partition the initial $m-1$ rolls into non-empty sets, one for each value (${m-1\brace q}q!$). We have $q$ choices for the last value.

Now we have

$${m-1\brace q} = (m-1)! [z^{m-1}] \frac{(\exp(z)-1)^q}{q!}$$

so the sum becomes

$$n (m-1)! [z^{m-1}] \sum_{q=1}^n {n-1\choose q-1} (\exp(z)-1)^q \\ = n (m-1)! [z^{m-1}] (\exp(z)-1) \sum_{q=0}^{n-1} {n-1\choose q} (\exp(z)-1)^q \\ = n (m-1)! [z^{m-1}] (\exp(z)-1) \exp((n-1)z) \\ = n (m-1)! [z^{m-1}] (\exp(nz)-\exp((n-1)z)).$$

Extracting coefficients we get

$$n (n^{m-1} - (n-1)^{m-1}) = n^m - n (n-1)^{m-1}$$

which yields for the proabability

$$1- \frac{(n-1)^{m-1}}{n^{m-1}}$$

which is

$$\bbox[5px,border:2px solid #00A000]{ 1- \left(1-\frac{1}{n}\right)^{m-1}.}$$

We list some very basic Maple code for total enumeration and closed forms as a means of clarifying the interpretation of the question that was used here.

PROB :=
proc(n, m)
option remember;
local ind, digits, rolls, last, res;

res := 0;

for ind from n^m to 2*n^m-1 do
digits := convert(ind, base, n);

rolls := digits[1..m-1];
last := digits[m];

if member(last, convert(rolls, set)) then
res := res + 1;
fi;
od;

res/n^m;
end;

X := (n,m)-> 1-(1-1/n)^(m-1);


Renark. It is actually much easier to count non-favorable outcomes than favorable ones. We have $n$ choices for the last roll and that choice must not occur among the first $m-1$ rolls, giving $(n-1)^{m-1}$ possibilities. The probability of the complementary event then becomes $n (n-1)^{m-1}/n^m$ as before.

The same simple Maple program also served at this MSE link.

I am not gonna go with massive calculations rather simple logic.

I think the probability will change with each dice roll.

On the first roll it doesn't matter what comes up as one cannot win on first roll(according to the rules you stated). Now on second roll the probability of winning will be 1/6 as the probability of repeating what came up on first roll is 1/6. On the third roll however the probability of winning shall increase to 2/6 and so on.

• I think you misunderstood the question. The fifth roll should be one of the previous rolls. – Earthliŋ Dec 8 '16 at 9:49
• To rephrase the question: Roll the dice 4 times. Now roll it a 5th time. You win if the 5th roll equals at least one of the first 4 rolls. For example let the first four results be (1, 1, 6, 3). Now the next roll is 1 -> win. Or it is 5 -> lose. – TobiMcNamobi Dec 8 '16 at 12:15
• @Earthliŋ sorry my bad ! – Rishabh Toki Dec 21 '16 at 5:56