# Fill this 5x5 number grid incrementally, either by moving two boxes diagonally or moving three boxes in a row or column

One day, a friend has shown me a 5 by 5 grid, challenging me to fill it with numbers from 1 to 25.
Obviously, it is not simple because there are some rules:

• The number 1 is placed in the center of the grid
• The numbers are placed in ascending order, either by moving two boxes diagonally or moving three boxes in a row or column (as shown in diagram)

How can you achieve that?

• What do you mean by "in ascending order"? In which direction? Jun 7, 2017 at 13:55
• And what do these "movements" have to do with filling the grid? Jun 7, 2017 at 13:55
• You have to fill the grid with numbers from 1 to 25. You start with the 1 in the center of the grid and you place the others numbers in an ascending order by moving two boxes diagonally or three boxes linearly. Sorry for the lack of precision, it's my first question. Jun 7, 2017 at 13:59
• Ah, gotcha. Now I'm sure I've seen this puzzle here before quite recently, but I can't find it! +1 anyway. Jun 7, 2017 at 14:00
• In other words you have to find a knight's tour on the 5x5 chessboard, except that you have to start in the centre, and instead of a knight you have a piece that can do move of the type {0,+-3}, {+-3,0}, and {+-2, +-2}. Jun 7, 2017 at 14:37

Definitely not unique, but here's one solution:

$$\begin{array} & 2 & 17 & 20 & 3 & 16 \\ 12 & 23 & 6 & 13 & 22 \\ 19 & 9 & 1 & 18 & 8 \\ 5 & 14 & 21 & 4 & 15 \\ 11 & 24 & 7 & 10 & 25 \end{array}$$

Found entirely with trial and error.

• Gratz, I calculated with computer there are 352 possible solutions.
– shy
Jun 7, 2017 at 15:22
• @shyos: Are there any solutions where you can jump from the $25$ back to the $1$? Jun 7, 2017 at 17:05
• @JaapScherphuis Sure. Just swap the 23 and 25 in this solution.
– user27014
Jun 7, 2017 at 18:19
• To avoid overcounting rotationally and axially symmetric solutions, why don't we WLOG say that 2 has to go in the TL corner, and hence 3 in the top row?
– smci
Mar 29, 2018 at 21:47

found another solution by trial and error

\begin{array} & 23 & 17 & 5 & 22 & 16 \\ 12 & 20 & 25 & 13 & 3 \\ 6 & 9 & 1 & 18 & 8 \\ 24 & 14 & 4 & 21 & 15 \\ 11 & 19 & 7 & 10 & 2 \end{array}

I kinda just made "boxes" where I could and used diagonals to transition the progression to the next "box"

It is indeed very similar to a KT (knight's tour). It is necessary to change the move rules, as a proper KT on a 5x5 grid is nearly trivial for an open path, and impossible for a closed path.

I was introduced to the problem in 2017, and became quite fascinated by it - so much that I wrote a program to find all solutions. It found (just as shyos pointed out) that there are 352 solutions when starting in the center (the problem as presented to me stipulated that the starting position could be anywhere on the grid). Of the 352 solutions, 96 were closed paths. By analyzing the program's results I was able to establish a fixed order to try for each successive move that will always lead to a closed path solution from any starting position, with no trial and error (backtracking) needed. If there is still any interest, I can post my algorithm. Here is one (closed path) solution for the center start position:

25 17  7 24 16
12  4 21 13  5
19  9  1 18  8
22 14  6 23 15
11  3 20 10  2


Step 1

Name the cells.

Step 2

Make a graph of the possible moves.

Step 3

Rearrange the nodes.

I removed the M. M connects to all four corners. Since we must start at M and then move to a corner we might as well start from the corner.

Step 4

Quite easily find a path visiting all nodes.
We must start from a corner and might as well end at another corner to reconnect to M.

I was surprised to see how few moves remain unused.

Step 5

We now have the sequence: MAPSDLOWHTEBQIXUFRCKNVGJY.
Go back to "square 1" and number the cells accordingly.