4

I'm considering the set of positive integers $n$ such that the integers from $1$ to $n$ can be arranged in a line such that every two consecutive numbers add to a perfect square. The smallest nontrivial such $n$ is $15$, with the ordering $8, 1, 15, 10, 6, 3, 13, 12, 4, 5, 11, 14, 2, 7, 9$.

$35$ also works, it turns out. Is there a name for these numbers? I tried searching on OEIS, but having only two terms is problematic...

Nishant
  • 9,495
  • I'm pretty certain that either this or a very similar question has been asked before. – Lucian Jun 06 '15 at 01:43
  • Very similar questions: http://math.stackexchange.com/questions/1168983/arranging-numbers-from-1-to-n-such-that-the-sum-of-every-two-adjacent-number#comment2413137_1168983 and http://math.stackexchange.com/questions/1169177/arrangement-of-integers-in-a-row-such-that-the-sum-of-every-two-adjacent-numbers?lq=1 as well as http://mathoverflow.net/questions/199677/arranging-numbers-from-1-to-n-such-that-the-sum-of-every-two-adjacent-number on MathOverflow. – Micah Jun 06 '15 at 02:37
  • It doesn't have a name, For $n \le 100$, $n = 15, 16, 17$ and all $n \ge 25$ (except $n = 86$ where the search using hamilton paths hangs) all works. Throwing the sequence $15,16,17,25,26,27,\ldots$ to OEIS doesn't return anything useful. The only match $OEIS A165776$ have some unwanted terms. – achille hui Jun 06 '15 at 02:38
  • @achillehui A090460 claims there are three solutions for $n=23$. Is that right? Then A090461 is your sequence with $23$ included. – Empy2 Jun 06 '15 at 02:51
  • @Michael okay, I make mistake in my search. 23 is allowed. One possible rearrangement is $$[22,3,1,8,17,19,6,10,15,21,4,12,13,23,2,14,11,5,20,16,9,7,18]$$ – achille hui Jun 06 '15 at 02:57
  • I had a question related to this sequence, but mine how many ways to arrange the numbers $1,...,n$ to get a sequence like this, provided a big enough $n$. – YoTengoUnLCD Jun 06 '15 at 03:39
  • Put the sequence itself into OEIS. That is, $8,1,15,10,6,...,9$ – Empy2 Jun 06 '15 at 02:29

2 Answers2

1

The problem of finding such a rearrangement of $1,\ldots, n$ can be restated in graph theory terms.

For any integer $n > 0$, consider a graph with $n$ vertices. Label the vertices from $1$ to $n$. For any two vertex $i$ and $j$, we join them by an edge when and only when $i + j$ is a prefect square. The problem of finding a desired rearrangement is equivalent to finding a Hamiltonian path in such a graph.

For example, following code in maixma

load(graphs);
H[i,j] := if(integerp(sqrt(i+j))) then 1 else 0;
G(n)   := from_adjacency_matrix(genmatrix(H,n,n));
hamilton_path(G(15))+1;

will return $$[9,7,2,14,11,5,4,12,13,3,6,10,15,1,8]$$

which is essentially the rearrangement you have in reverse order.

Using codes above, I have checked for $n \le 100$, the set of $n$ that allow such an arrangement are $15,16,17,23^{\color{blue}{[1]}}$ and all $n \ge 25$ (except for $n = 86$ where above code hangs).

As pointed out by Michael, a search on this numbers return OEIS A090461 and $86$ is also allowed.

Notes

  • $\color{blue}{[1]}$ Thanks for Michael pointing out my error on $23$.
achille hui
  • 125,323
0

See sequence A071983:

Square chains: the number of permutations (reversals not counted as different) of the numbers 1 to n such that the sum of any two consecutive numbers is a square.

Timothy Chow
  • 1,174