21, 28, 8, 1, 15, 10, 26, 23, 2, 14, 22, 27, 9, 16, 20, 29,
7, 18, 31, 5, 11, 25, 24, 12, 13, 3, 6, 30, 19, 17, 32, 4
where 21 + 4 is also a (perfect) square.
The possibility of such cycles grows with N, but I admit I cannot see any direct connection of numbertheoretic properties of N.
]]>Take the set {1, …, N} as the set of nodes of a graph. Tho nodes n, m are connected by an edge iff n+m is a (perfect) square. You can draw this graph for N = 15 within a minute or so:
8

15 — 1 — 3 — 13 — 12 — 4 — 5 — 11 — 14 — 2 — 7 — 9
 
10 —— 6
to see there is only one admissible path through this graph touching all nodes (exaxctly) ones, and there is no “toroidal”, i.e. closed, path.
With R, it is easy to set up these graphs and to visualize a 2dim. layout applying, for instance, the ‘igraph’ package. This package also is able to efficiently find a Hamiltonian path, a path that meets each node exactly ones — even for huge values of N.
By the way, there are no such Hamiltonian cycles for N <= 30.
HW
]]>