**From New Scientist #2130, 18th April 1998** [link]

Imagine an 8 × 8 chess board and imagine that in each square of the board there is written one of the following four instructions:

Turn right;

Turn left;

Go straight ahead;

Go back.

An ant is placed at the centre of the bottom left corner square. She walks, parallel to the bottom edge of the board, until she reaches the centre of the next square. She reads the instruction in the square she is in and sets off walking in the direction specified by that instruction. She walks in a straight line until she reaches the centre of a square or until she walks off the board; in the latter case, her walk stops. She continues her walk in this way, from square to square, obeying the instruction each time. She walks until she reaches the top right corner square, or she walks off the board; when either happens, her walk stops. In the former case it is called a successful walk.

Answer each of the following questions, “Yes” or “No”.

1. Is it possible to find a successful walk in which the ant repeats some part of her walk?

2. Is it possible to find a walk in which the ant does not repeat the first part of her walk but does repeat some part of her walk?

3. Is it possible to find a successful walk in which the ant visits the top left-hand corner square of the board more than once?

4. Suppose now that the board is 4 × 4. Is is possible to write an instruction in each square, using each of the four different instructions four times, so that the ant’s walk visits every square of the board at least once?

[enigma975]

### Like this:

Like Loading...

The instructions are fixed, and the ant’s process is deterministic. So if the ant enters a square it has been in before from the same direction as before it is forced to repeat the instructions in exactly the same way until it finds itself entering the square again from the same direction. So it will be doomed to repeat the loop forever.

This answers the first two parts of the question:

Solution:1. No; 2. No.We call the instructions R (“turn right”), L (“turn left”), A (“straight ahead”) and B (“back”)

In order for the ant to visit the top left square more than once it must enter it from two different directions. There are only two possible directions the square can be entered from – from below (heading north) or from the right (heading west).

When entered from below it can only instruct R or B. When entered from the right it can only instruct L or B. So in order to be entered more than once it would have to contain the instruction B.

So we can think about what the instruction in the square below would be. It can’t be B, as that would create an inescapable loop. It can’t be L, as we would have to enter the square from the left, which is impossible. And it can’t be R, as if we entered from the right, turned right, advanced to the corner, turned back, we would then have to turn R and end up off the board. So the only option is A, but this just pushes the issue down to the next square, which must also be A, and so on until we see the entire rest of the left-hand edge of the grid would need to be filled with A’s entered from below, but the last one cannot be entered from below, so the scenario is not possible.

Solution:3. No.For the final part we can write a program to look for suitable grids.

This Python 3 program runs in 675ms.

Run:[ @repl.it ]Solution:4. Yes.There are five possible grids. The ant can manage a walk of 20, 22 or 24 steps.

Here are diagrams of the grids and the walks: