I came up with a question while doing a project on simulation on some experiments regarding dice. The question was:
On average, how many times must a 6-sided die be rolled until two rolls in a row differ by 1
Like, suppose I roll a $3$, then the next roll should be either a $4$ or a $2$.
I approached my problem with the concept of similar expectations.
Let $E$ denote the required expected number of rolls and $E_i$ denote the required expected number of rolls after rolling an $i$. Thus, we will get one equation as $$E=1+\frac{1}{6}\left(\sum_{i=1}^6 E_i\right)$$
Now, if we observe, we can find that $E_1=E_6$. Thus, we can formulate another equation which goes on like $$E_1=\underbrace{\frac{1}{6}E_1}_{\text{getting a 1 again in the next throw}}+\underbrace{\frac{1}{6}}_{\text{getting a 2 in the next throw}}+\underbrace{\frac{4}{6}E}_{\text{getting anything else in the next throw}}$$ Solving this, we get $E_1=\frac{1+4E}{5}$. Now, again, we observe that $E_2=E_3=E_4=E_5$. Once again, we can formulate a similar formula as before $$E_2=\underbrace{\frac{1}{6}E_2}_{\text{getting a 2 again in the next throw}}+\underbrace{\frac{2}{6}}_{\text{getting a 3 or 1 in the next throw}}+\underbrace{\frac{3}{6}E}_{\text{getting anything else in the next throw}}$$ Solving, we find $E_2=\frac{2+3E}{5}$. Plugging these values to the original equation, we find that $$E=1+\frac{1}{3}E_1+\frac{2}{3}E_2\\ \implies E=4$$
Now, when I ran a Monte Carlo simulation for the above experiment (in R), the answer that came was different. I am providing my code below for any doubts:
rolls<-function() #function
{
x<-sample(1:6,1);y<-sample(1:6,1) #roll twice
i=2 #set the roll counter
while(abs(x-y)>1) #while their absolute diff is more than 1
{
x<-y;y<-sample(1:6,1) #replace the second roll with the first one and roll
i=i+1 #increase the counter
}
return(i) #return no. of rolls
}
mean(replicate(5,mean(replicate(10000,rolls()))))
This code gave me an answer of 4.69556, which, when rounded off, answers this question as $5$. I am stuck here as to finding out what is wrong with my mathematical argument (the reason being I am pretty confident that the simulation is fine).
I did some surfing for a similar question and the explanation and I found this same question posed in this article (Problem-4). However, here, the author has assumed that $E_2=E_5,E_3=E_4$ but not $E_2=E_3$. I don't understand why this is the case. After all, they are just numbers like $2,3,4,5$ and each of them has two distinct sets of possible feasible outcomes (which are also similar) to this experiment. My question is, why is it that $E_2\neq E_3$?
I'd be glad if someone cleared my doubt.
My first instinct was the same as yours; but I think I understand now why $E_2\ne E_3$.
Suppose our current roll is a $3$. There is a $2$ in $6$ chance that we win on the next roll; however, there's also a $2$ in $6$ chance that we obtain an extreme value ($1$ or $6$) that makes it harder to win next turn.
On the other hand, suppose our current roll is a $2$. There's still a $2$ in $6$ chance that we win on the next roll; however, there's only a $1$ in $6$ chance that we obtain a non-winning extreme value ($6$). This, I think, is the explanation of why $E_2<E_3$.