I'm trying to solve this probability exercise:
You have 100 marbles numbered 0 to 99 in a bag. You repeatedly draw a marble from the bag (all marbles being equiprobable), note its number, and replace it in the bag. On average, how many of the marbles numbered 1 through 99 will have been drawn from the bag one or more times before drawing marble #0?
I guessed a trial would consist of picking and replacing marbles at succession and counting failures. But the solution disagrees. What am I missing logically? I coded a trial in Mathematica like this:
trial :=
With[{marbles = Range[0, 99]},
Module[{
count = 0,
pick = RandomChoice[marbles]},
While[pick != 0,
count++;
pick = RandomChoice[marbles]];
count]]
And approximate the answer:
With[{n = 10000},
N@Mean@Table[trial, {n}]]
Update
I didn't understand the text, it asks for the number of distinct marbles drawn before the #0. The working code is:
trial :=
With[{marbles = Range[0, 99]},
Module[{pick, picked = {}},
pick = RandomChoice[marbles];
While[pick != 0,
If[! MemberQ[picked, pick],
AppendTo[picked, pick]];
pick = RandomChoice[marbles]];
Length[picked]]]
Drawing the $\#42$ marble, then the $\#42$, then the $\#42$, then the $\#0$ only counts as one failure before the first success. If we were counting them as separate failures, then the number of failures before the first success would have one of the versions of the geometric distribution, and would have mean $99$. But that is not the situation here. Now to the solution, which will use the method of indicator random variables.
For $i=1$ to $99$, let $X_i=1$ if marble $i$ is drawn before marble $0$, and let $X_i=0$ otherwise. Then the number $Y$ of different bad marbles drawn before the first $0$ marble is $X_1+\cdots+X_{99}$. We have $E(X_i)=\frac{1}{2}$, and therefore by the linearity of expectation $E(Y)=\frac{99}{2}$.