OFFSET
1,2
COMMENTS
The sequence is finite and ends at the 111th move, which takes the knight to the square numbered 36 (the leftmost square on the 6th row).
The squares on the board are numbered as follows:
. . . . . . .
. . . . . . .
. . . . . . .
+----+----+----+----+----+----+----+
| 49 | 48 | 47 | 46 | 45 | 44 | 43 | ...
ending +----+----+----+----+----+----+----+
square ---> | 36 | 35 | 34 | 33 | 32 | 31 | 42 | ...
+----+----+----+----+----+----+----+
| 25 | 24 | 23 | 22 | 21 | 30 | 41 | ...
+----+----+----+----+----+----+----+
| 16 | 15 | 14 | 13 | 20 | 29 | 40 | ...
+----+----+----+----+----+----+----+
| 9 | 8 | 7 | 12 | 19 | 28 | 39 | ...
+----+----+----+----+----+----+----+
| 4 | 3 | 6 | 11 | 18 | 27 | 38 | ...
starting +----+----+----+----+----+----+----+
square ---> | 1 | 2 | 5 | 10 | 17 | 26 | 37 | ...
+----+----+----+----+----+----+----+
LINKS
N. J. A. Sloane and Brady Haran, The Trapped Knight, Numberphile video (2019).
MATHEMATICA
findvalue[{i_, j_}] := If[j > i, (j - 1)^2 + 2 j - i, (i - 1)^2 + j];
possiblemoves[{i_, j_}, prev_List] :=
Block[{moves = {{i + 2, j + 1}, {i + 2, j - 1}, {i + 1,
j + 2}, {i + 1, j - 2}, {i - 1, j + 2}, {i - 1, j - 2}, {i - 2,
j + 1}, {i - 2, j - 1}}, list},
list = DeleteCases[moves, {x_, y_} /; x < 1 || y < 1];
Complement[list, Intersection[list, prev]]];
findnextmove =
Block[{listofmoves = #, nextmove, poss},
pos = possiblemoves[listofmoves[[-1]], listofmoves];
If[Length[pos] > 0,
nextmove = Sort[({findvalue[#], #} &) /@ pos][[1, 2]];
AppendTo[listofmoves, nextmove], listofmoves]] &;
findvalue /@ FixedPoint[findnextmove, {{1, 1}}]
CROSSREFS
KEYWORD
nonn,fini,full,walk
AUTHOR
Roman Mecholsky, May 12 2021
STATUS
approved