A $5 \mathrm{~cm}$ edge-length cube-shaped cheese has Pacworm, the cheese worm, sitting in its center. The worm eats through the cheese in such a way that it always advances $1 \mathrm{~cm}$ parallel to one of the edges at a time, then changes direction, being careful that when it starts in a new direction, there is more than $1 \mathrm{~cm}$ of untouched cheese in front of it. Assuming that at both the start and when changing direction, the worm chooses one of the possible directions with equal probability, what is the probability that after traveling $5 \mathrm{~cm}$, it will be at most $0.8 \mathrm{~cm}$ away from one of the edges?
# Solution.

Let one centimeter be one unit. Consider the $4 \times 4 \times 4$ "inner cube" whose edges are parallel to those of the cheese, and whose center coincides with the center of the cheese. This cube defines a $1 \times 1 \times 1$ grid. Let's set up a coordinate system whose axes are parallel to the edges of the cubes, and whose origin coincides with the center of the cubes. The inner cube contains 125 grid points, and the mouse can only step on these. Among these points, those that are not on the edges of the inner cube will be at least one unit away from each edge of the cheese.

![](https://cdn.mathpix.com/cropped/2024_05_02_11422c57acc3b30b1361g-1.jpg?height=453&width=458&top_left_y=424&top_left_x=823)

The distance of the points on the edges from the nearest edge of the cheese cube is $\sqrt{2 \cdot 0.5^{2}} \approx 0.707$. Therefore, the mouse must get out to one of the edges of the inner cube. For this, the deviation in two of the $x, y, z$ directions from the center must be two. More than two is not possible, as it would exit the cube. With each step, it changes one of its deviations. The mouse takes five steps. Since it changes direction after each step, it cannot increase the same deviation twice in a row.

The mouse can make its first two steps in any direction, always starting in one direction and then in a perpendicular direction. Up to this point, every case is good. Let the first direction be $x$, and the second be $y$. Now it can turn in four directions (since there is no untouched cheese layer behind it): $x, -x, z$, or $-z$. If it turns in the $-x$ direction, it will not be able to reach any edge. (Since its deviation is $(0,1,0)$, it would need to change a minimum of 3 in two steps.)

If it goes in the $x$ direction, which has a probability of $\frac{1}{4}$, it will reach the surface of the inner cube, and it can still go in four directions: $y, -y, z, -z$. If it goes in the $-y$ direction, its deviation will be $(2,0,0)$, from which it cannot reach any edge in one step.

If it continues in the $y$ direction with a probability of $\frac{1}{4}$, it will reach an edge, from where it cannot go in the $x$ direction, only in the $-x, z$, and $-z$ directions. If it chooses $z$ or $-z$, it will remain on the edge, with deviations of $(2,2,1)$ or $(2,2,-1)$, with a probability of $\frac{2}{3}$. Thus, here it reaches the edge with a probability of $\left(\frac{1}{4} \cdot \frac{2}{3}\right)$.

If it goes in the $z$ (or $-z$) direction, with a probability of $\frac{1}{4}$ (a total of $\frac{1}{2}$), its deviation will be $(2,1,1)$, meaning it cannot go in the $x$ direction. Therefore, it is left with $y, -y, -x$. Since it cannot change its $z$ deviation, it will only reach the edge if it goes in the $y$ direction, with a probability of $\frac{1}{3}$. Thus, the probability of reaching the edge in the $z$ and $-z$ directions is $\left(\frac{1}{2} \cdot \frac{1}{3}\right)$.

If after $(1,1,0)$ it does not go in the $x$ direction but in the $z$ or $-z$ direction (with a probability of $\frac{1}{2}$), its deviation will be $(1,1,1)$. It can still go in four directions, but if it goes in the $-y$ or $-x$ direction, none of its deviations will be 2 before the last step, so it cannot reach any edge. Therefore, here it goes in the right direction with a probability of $\frac{1}{2}$. No matter which direction it goes, it reaches a face. In the case of $(2,1,1)$, it can go in four directions $(y, -y, z, -z)$, and it will reach the edge if it goes in the $y$ or $z$ direction, so the probability is again $\frac{1}{2}$. If it goes in the $y$ direction, it will reach the edge by choosing the $x$ or $z$ direction, so the probability is again $\frac{1}{2}$.

Thus, the probability of reaching the edge here is $\left(\frac{1}{2} \cdot \frac{1}{2} \cdot \frac{1}{2}\right)$.

Regardless of the direction of the first two steps, these will always be the probabilities. Adding these probabilities together, the desired probability is:

$$
\frac{1}{4} \cdot\left(\frac{1}{4} \cdot \frac{2}{3}+\frac{1}{2} \cdot \frac{3}{3}\right)+\frac{1}{2} \cdot \frac{1}{2} \cdot \frac{1}{2}=\frac{1}{12}+\frac{1}{8}=\frac{5}{24}
$$