OFFSET
1,2
COMMENTS
Arrange A000027, the natural numbers, into a (square) spiral, say clockwise as shown in A068225. Read the numbers from the resulting counterclockwise spiral of the same shape that also begins with 1 and this sequence results. - Rick L. Shepherd, Aug 04 2006
Contribution from Hieronymus Fischer, Apr 30 2012: (Start)
The sequence may also be defined as follows: a(1)=1, a(n)=m^2 (where m^2 is the least square > a(k) for 1<=k<n), if the minimal natural number not yet in the sequence is greater than a(n-1), else a(n)=a(n-1)-1.
A reordering of the natural numbers.
The sequence is self-inverse in that a(a(n))=n.
(End)
REFERENCES
R. Honsberger, "Ingenuity in Mathematics", Table 10.4 on page 87.
Suggested by correspondence with Michael Somos.
LINKS
FORMULA
Contribution from Hieronymus Fischer, Apr 30 2012: (Start)
a(n)=a(n-1)-1, if a(n-1)-1 > 0 is not in the set {a(k)| 1<=k<n}, else a(n)=m^2, where m^2 is the least square not yet in the sequence.
a(n)=n for n=k(k+1)+1, k>=0.
a(n+1)=(sqrt(a(n)-1)+2)^2, if a(n)-1 is a square, a(n+1)=a(n)-1, else.
a(n)=2*(floor(sqrt(n-1))+1)*floor(sqrt(n-1))-n+2. (End)
EXAMPLE
a(2)=4=2^2, since 2^2 is the least square >2=a(1) and the minimal number not yet in the sequence is 2>1=a(1);
a(8)=6=a(7)-1, since the minimal number not yet in the sequence (=5) is <=7=a(7).
MATHEMATICA
Flatten[Table[Range[n^2, (n-1)^2+1, -1], {n, 10}]] (* Harvey P. Dale, Jan 10 2016 *)
With[{nn=20}, Flatten[Reverse/@TakeList[Range[nn^2], Range[1, nn, 2]]]] (* Requires Mathematica version 11 or later *) (* Harvey P. Dale, Jan 28 2019 *)
PROG
(PARI) a(n)=local(t); if(n<1, 0, t=sqrtint(n-1); 2*(t^2+t+1)-n)
CROSSREFS
KEYWORD
nonn
AUTHOR
N. J. A. Sloane, May 02 2000
STATUS
approved