# Expected value of number of sequences

We throw a regular cube $20$ times and write the results in a row. we look at the row and count the number of $121$ sequences.

(For example: if we have $11626451214435612121$ then we get three $121$ sequences).

I want to compute the expected value of the number of sequences $121$

what I have tried is to define $I_i=\begin{cases} 1 & \text{121 sequence begin in the i place} \\ 0 & \text{otherwise} \end{cases}$

and the number of sequences will be $R(121)=\sum_{n=1}^{20}I_i$, so we get $E[R(121)]=\sum_{n=1}^{20}E[I_i]$

Can you help me to proceed or give me other way to solve this if I'm wrong?

• Your approach of the problem is okay. Only note that the right expression is $\sum_{i=1}^{18} \mathbb E[I_i]$. Just finish the job by finding $\mathbb E[I_i]$ Commented Jun 27, 2017 at 14:50
• Note that $\mathbb E[I_i] = \mathbb E[I_1]$ for $1 \le i \le 18$ Commented Jun 27, 2017 at 15:00
• As an aside only loosely related to the question, I believe the expected number of throws until $121$ first appears is $6^3+6$, slightly more than $1/\mathbb E[I_1]$ Commented Jun 27, 2017 at 15:11

$$E(R(121)) = \sum_{i=1}^{18}E(I_i)$$

$$E(I_i) = P(\text{121 sequence begins in ith place}) = \frac{1}{6^3}$$

Edit: As requested in the comment by @timi,

$$Var(R(121)) = \sum_{i=1}^{18}\sum_{j=1}^{18}Cov(I_i, I_j)$$

where

• $Cov(I_i, I_i) = Var(I_i) = E(I_i^2) - E(I_i)^2$ in which $E(I_i^2) = \frac{1}{6^3}$.

• $Cov(I_i, I_{i-1}) = E(I_iI_{i-1}) - E(I_i)E(I_{i-1})$ where $E(I_iI_{i-1}) = 0$ because $I_{i-1}=1 \wedge I_{i}=1$ is an impossible event.

• $Cov(I_i, I_{i-2}) = E(I_iI_{i-2}) - E(I_i)E(I_{i-2})$ where $E(I_iI_{i-2}) = P(I_i=1|I_{i-2}=1)P(I_{i-2}=1) = \frac{1}{6^2}\frac{1}{6^3}$, that is for the case of $12121$.

• and $Cov(I_{i}, I_{i-k}) = 0, \forall k \geq 3$.

• Thanks, expiTTp1z0.
– timi
Commented Jun 27, 2017 at 15:15
• Just one more question. If I want to calculate the Var(the number of sequences 121). Is there any formulafor this? thanks.
– timi
Commented Jun 27, 2017 at 15:20
• Check the edited answer. Commented Jun 27, 2017 at 15:33
• @timi let me know if you don't understand something. I wrote quickly. Commented Jun 27, 2017 at 15:39
• understood! Thanks!
– timi
Commented Jun 27, 2017 at 15:52