14. New Year's Problem (recommended for 8th grade, 4 points). On the New Year's table, there are 4 glasses in a row: the first and third are filled with orange juice, while the second and fourth are empty. While waiting for guests, Vanya absent-mindedly and randomly pours the juice from one glass to another. In one move, she can take a full glass and pour all its contents into one of the two empty glasses.

Find the expected number of pourings after which, for the first time, everything will be the opposite: the first and third glasses will be empty, and the second and fourth will be full.
Solution. We will encode full glasses with the digit 1 and empty ones with the digit 0. We will construct a graph of possible pourings (Fig. 4). This graph turns out to be the graph of an octahedron. From each state to any adjacent one, one can move with a probability of $1 / 4$, and each edge is "traversable" in both directions.

From the initial state (1010) to the final state (0101), one can transition through any of the remaining four states. Let's identify these four intermediate states. We get a simpler graph with three vertices (Fig. 5).

For brevity, let's denote the initial and final states by $A$ and $C$, and all intermediate states by a single vertex $B$, without distinguishing between them. We will make the edges directed, showing all possible movements in the graph, except for the edge $C \rightarrow B$, which we do not need, since we are interested in the moment of the first arrival of the random process at vertex $C$. We will write the probabilities of the corresponding steps next to the edges. For example, the probability of the step $A \rightarrow B$ is 1, and the probability of the reverse step $B \rightarrow A$ is $1 / 4$. The probability of the step $B \rightarrow B$ is $1 / 2$.

Let $X$ be the random variable "the number of steps leading from A to C for the first time," and $Y$ "the number of steps leading from B to C for the first time."

It is clear that from $A$ one can only go to $B$, and after that, to reach vertex $C$, it will take $Y$ steps. Therefore,

$$
X=1+Y
$$

![](https://cdn.mathpix.com/cropped/2024_05_06_e14c9bd69fbda0eec36cg-15.jpg?height=497&width=505&top_left_y=274&top_left_x=1415)

Fig. 4

Exiting from $B$, the process can go three ways, each of which we will invent an indicator for: let $I_{A}, I_{B}$, and $I_{C}$ be three random variables, each of which is 1 if the process transitions from point $B$ to $A, B$, or $C$ respectively, and 0 otherwise.

If the process from $B$ reaches the initial point $A$, then one step is spent and it will take another $X_{1}$ steps to reach $C$, and the quantities $X$ and $X_{1}$ are identically distributed. If the process from $B$ reaches $B$ again, then one step is spent, but nothing changes and it will take $Y_{1}$ steps to reach $C$, and the quantities $Y$ and $Y_{1}$ are identically distributed. Only in the case of transitioning to $C$ does the process end. We get the equation

$$
Y=I_{A}\left(1+X_{1}\right)+I_{B}\left(1+Y_{1}\right)+I_{C} \cdot 1
$$

The indicators $I_{A}, I_{B}$, and $I_{C}$ relate to the step taken from point $B$, while the quantities $X_{1}$ and $Y_{1}$ relate to subsequent steps. Therefore, the quantities $I_{A}$ and $X_{1}$ are independent, and $I_{B}$ and $Y_{1}$ are independent. Transitioning to mathematical expectations in equations (1) and (2), we get the system

$$
\left\{\begin{array}{l}
\mathrm{E} X=1+\mathrm{E} Y, \\
\mathrm{E} Y=\mathrm{E} I_{A} \cdot\left(1+\mathrm{E} X_{1}\right)+\mathrm{E} I_{B} \cdot\left(1+\mathrm{E} Y_{1}\right)+\mathrm{E} I_{C}
\end{array}\right.
$$

Let's find the mathematical expectations of the indicators:

$$
\mathrm{E} I_{A}=\mathrm{P}\left(I_{A}=1\right)=\mathrm{P}(B \rightarrow A)=\frac{1}{4}, \mathrm{E} I_{B}=\frac{1}{2} \text { and } \mathrm{E} I_{C}=\frac{1}{4} .
$$

Let $\mathrm{E} X=\mathrm{E} X_{1}=x$ and $\mathrm{E} Y=\mathrm{E} Y_{1}=y$. The system takes the form

$$
\left\{\begin{array}{l}
x=1+y \\
y=1+\frac{1}{4} x+\frac{1}{2} y,
\end{array}\right.
$$

Answer: 6.

Comment. The solution can be made more concise if we use the properties of conditional mathematical expectations.