# Eating a cake from the inside.

Imagine that you are in the centre of a cube of cake with a known size. In order to move you must eat the surrounding cake but you can only move within the restraints of the six obvious directions $(x+1,x-1,y+1,y-1,z+1,z-1)$.

The puzzle is- can you eat the entire cake in such a fashion without overlapping parts of the cake which you have already eaten.

I would actually like to answer this question for a practical purpose and I have put much thought into it. From what I understand it may only be possible by moving diagonally (applying $2$ or more movements of different axis at the same time-such as $x-1$ and $y-1$).

I have asked my maths teacher and some of my friends but I am sure there must be a solution.

• I must add that I do not have the mathematical experience to use the correct terminology- being only 14.
– will
Jan 12, 2014 at 9:05
• "I would actually like to answer this question for a practical purpose" User2592835 is trapped inside a cake! Send help.
– user856
Jan 13, 2014 at 0:02
• That cake tricked me.
– will
Jan 13, 2014 at 15:44

This is a supplement to others answer. In particular, MathBob's suggestion that it is possible to completely cover a cube of side $5+4k$ start from the center.

Following is an example using the $5\times 5 \times 5$ cube. We are showing the 5 layers of the cube from top to bottom. The number in each slot is the order one visit/eat the corresponding piece of cake.

$$\left[\begin{array}{rrrrr}23&24&25&26&\color{#bbbb00}{27}\\22&9&10&11&12\\21&8&\color{orange}{3}&4&13\\20&7&6&5&14\\19&18&17&16&15\end{array}\right] \left[\begin{array}{rrrrr}32&31&30&29&\color{#00bb00}{28}\\33&46&45&44&43\\34&47&2&\color{blue}{51}&42\\35&48&49&50&41\\36&37&38&39&40\end{array}\right] \left[\begin{array}{rrrrr}71&72&73&74&75\\70&57&58&59&60\\69&56&\color{red}{1}&\color{magenta}{52}&61\\68&55&54&53&62\\67&66&65&64&63\end{array}\right]\\ \left[\begin{array}{rrrrr}80&79&78&77&\color{purple}{76}\\81&94&93&92&91\\82&95&100&99&90\\83&96&97&98&89\\84&85&86&87&88\end{array}\right] \left[\begin{array}{rrrrr}121&122&123&124&125\\120&107&108&109&110\\119&106&101&102&111\\118&105&104&103&112\\117&116&115&114&113\end{array}\right]$$

1. Start from the center of cake (the red $\color{red}{1}$ in the $3^{rd}$ layer), one eat/move upward until one reaches the center of the top layer (the orange $\color{orange}{3}$ in $1^{st}$ layer).
2. Spiral outwards until one exhaust all slots in $1^{st}$ layer and end at a corner (the yellow corner $\color{#bbbb00}{27}$).
3. Move downwards to a corner (the green corner $\color{#00bb00}{28}$ ) in $2^{nd}$ layer.
4. Spiral inwards until one exhaust all slots in $2^{nd}$ layer and end at a slot (the blue $\color{blue}{51}$ ) next to the center in $2^{nd}$ layer.
5. Move downwards to a slot (the magenta $\color{magenta}{52}$) in the $3^{rd}$ layer.

We then repeat essentially the same steps $2-5$ until we exhaust all the layers. When we reach a layer below the center (i.e the $4^{th}$ and $5^{th}$ layer in this case ), step 4 need a slight modification. Instead of ending at a slot next to the center, one should end at the center for that particular layer.

When the side of the cube is of the form $5+4k$, there are even number of layers below the center and we enter the first layer below the center at a corner (in our example, the $\color{purple}{76}$ in $4^{th}$ layer), we won't have any problem to complete fill the layers below the center.

In contrast, for cube whose side is of the form $3+4k$, we will enter the first layer below center of cube near the center of layer. We will get into problem how to cover the center of that layer.

I hope this example is clear enough how to cover cube of side $5 + 4k$.

Update

Following is a little animation showing how the $5 \times 5 \times 5$ cube can be visited. For the purpose of visualization, I have flipped the cube vertically. In the animation, the $1^{st}$ layer we build is the bottom layer instead of the top layer discussed above.

$\hspace1.2in$

• Second to last paragraph, don't you mean form 3 + 4k ? Consider when k = 0. I liked the pattern you came up with. (I had a different pattern that also worked where I eliminated the 3 x 3 centers and left the outside edge.) Jan 12, 2014 at 13:32
• @MathBob Yes, it should be $3+4k$. What a dumb mistake. Jan 12, 2014 at 13:34

If you are exactly in the middle and can only go in the 6 directions, it is like being in a cube with an odd number of sides (in order to have an exact middle cube). If you colored the cubes alternately black and white with the middle one white, then you are in the white cube and there are one more black cubes than there are white cubes (counting the middle cube.) (This would be for a 3 x 3 x 3 or a 7 x 7 x 7 cube.) This is because an odd sided cube has n x n x n cubes which is an odd number of cubes, so there has to be more blacks than whites by 1 (or visa-versa in 5 x 5 x 5 or 9 x 9 x 9 cubes etc.) So, if you eat the white one first (the one you are in) then eat alternately black and then white cubes, you end up having to eat a white cube then there are two black cubes left and you eat one of them and then you cannot eat a white cube!

So, it is impossible as far as I can see. I need to edit my answer. If the number of units on each side is 5+4k (where k=0,1,2,...) then I think it can be done because the greater number of white squares will end up with a white one in the middle. But I think 3+4k units on each side cannot be done because of the situation I was describing. On 3+4k sided cubes the middle square is a different color than the corner squares. This one cannot be done. (If you are in the middle square and it is white and you eat it, there will be two more black squares than white.) Whereas on 5+4k sided cubes, the middle square is the same color as the corner squares and after you eat the middle square there will be the same number of squares of each color.

So, it can always be done if you break the cube into the proper number of odd units on each side. I think this is the correct answer, but there may be more complications than what I have been discussing. The 3+4k sided cubes definitely cannot be done.

• This argument does not use the fact that one starts in the center of the cube, but only that one must alternately eat white and black. But any cube can be eaten properly if one starts in a corner of the cube. Each layer may be eaten by a process of going across a row, going down to the end of the next row then back to its start, etc, winding up at the diametrically opposite corner of that layer. Then one can drop down to the next layer and do the same thing in reverse, and so on. The argument must use something re. starting at central cube, not just black/white cubes. Jan 12, 2014 at 16:23
• I like the concept of black and white cubes.So essentially we are talking about a Batenburg?
– will
Jan 12, 2014 at 18:39

Preamble: comparison with MathBob's approach. I realized after entering this that the sets $E,O$ used below can also be described as the set of triples $(x,y,z)$ for which $x+y+z$ is even or odd, respectively. So if the middle cube is white, this is the same coloring used by MathBob, where the count of whites is the count of $E$, the black count of $O$, What I found hard to see was how the value of $n$ mod $4$ entered into why there are one more of which color. So what I did was to actually count these numbers, and it came out that in the $n=4k+3$ case there is one more black (odd) than white. I don't know if there is a simple way to see that short of actually counting the two numbers as I did below. I left the rest as it was, using taxicab distance language.

This answer is to show the impossibility in case $n=4k+3,\ k\ge 0$ [The procedure for eating the cake if $n=4k+1$ has already been shown by achille hui and mentioned by MathBob.]

The idea is to partition the cubes into two sets $E,O$ of those points whose taxicab distance from the origin is even or odd respectively. It can be shown (see below) that for $n=4k+3$ we have $$|E|=32k^3+72k^2+54k+13,\\ |O|=32k^3+72k^2+54k+14.$$ Every legal move is from a point in $E$ to one in $O$, or vice-versa. The center of the cube is in $E$, and since we are to start there, the tour cannot be made since there is one more element in $O$ than there is in $E$.

proof of counts for $|E|,|O|.$ In the set $\{-2k-1,\cdots,2k+1\}$ of values available for a coordinate of a point $(x,y,z)$ in the $n$-cube (with $n=4k+3$) there are $2k+1$ even integers and $2k+2$ odd integers. If $(x,y,z)$ is at even taxicab distance from $(0,0,0)$ then either all three coordinates are even or else two are odd and the third even. Since there are three ways the odd,odd,even case can occur, the count for $|E|$ is $$|E|=(2k+1)^3+3(2k+1)(2k+2)^2,$$ which when expanded is our claimed count for $|E|.$ On the other hand if $(x,y,z)$ is at odd taxicab distance from the origin, then either all three coordinates are odd or else (three ways for this) one is odd and two are even. This gives the $|O|$ count as $$|O|=(2k+2)^3+3(2k+2)(2k+1)^2,$$ which expands to our claimed count for $|O|$. As a check one finds that $|E|+|O|=(4n+3)^3.$

Final note: If one does the above calculation for the (shown to be possible) case when $n=4k+1,\ k \ge 1$, it turns out that $|E|=|O|+1$, which means starting inside $E$ (center of cube) this parity argument does not rule out a path. (That's a good thing, given the constructions of actual solutions in the $4k+1$ case.)

• It will be easier to count the difference $O-E$. For odd $n = 2\ell+1$, the cube can be broken down into $n$ layers. Each layer can be broken down into a center piece plus $\ell$ rings. Since the lengths of the rings are all multiples of $8$, they contribute nothing to the difference $O-E$. In the end, one only need to count the center piece from each layer and it is sort of obvious $O-E = (-1)^{\ell-1}$. Jan 13, 2014 at 3:18