OFFSET
0,2
COMMENTS
One of eight possible knight's tours. Squares are numbered in a clockwise spiral. Enumerates all positive integers.
A description of the method to construct the tour is provided in A306659. - Hugo Pfoertner, May 11 2019
LINKS
Hugo Pfoertner, Table of n, a(n) for n = 0..1088
Frank Ellermann, Sequences based on a spiral of the natural numbers
Hugo Pfoertner, Illustration of tours corresponding to A068608-A068615, (2019).
Dan Thomasson, Knight's Tour Art, (2001-2014).
PROG
(PARI) \\Ellermann's clockwise square spiral, first step (0, 0) -> (0, 1)
y=vector(10000); L=0; d=1; n=0;
for(r=1, 100, d=-d; k=floor(r/2)*d; for(j=1, L++, y[n++]=k); forstep(j=k-d, -floor((r+1)/2)*d+d, -d, y[n++]=j));
x=vector(10100); L=1; d=-1; n=0;
for(r=1, 100, d=-d; k=floor(r/2)*d; for(j=1, L++, x[n++]=-k); forstep(j=k-d, -floor((r+1)/2)*d+d, -d, x[n++]=-j));
\\ Position in spiral
findpos(i, j)={my(size=(2*max(abs(i), abs(j))+1)^2); forstep(k=size, 1, -1, if(i==x[k]&&j==y[k], return(k)))};
atan2(y, x)=if(x>0, atan(y/x), if(x==0, if(y>0, Pi/2, -Pi/2), if(y>=0, atan(y/x)+Pi, atan(y/x)-Pi)));
angle(v, w)=atan2(v[1]*w[2]-v[2]*w[1], v[1]*w[1]+v[2]*w[2]);
move=[2, 1; 1, 2; -1, 2; -2, 1; -2, -1; -1, -2; 1, -2; 2, -1]; \\ 8 Knight moves
m=6; b=matrix(2*m+1, 2*m+1, i, j, 0); setb(pos)={b[pos[1]+m+1, pos[2]+m+1]=1};
getb(pos)=b[pos[1]+m+1, pos[2]+m+1];
inring(n, p)=!(abs(p[1])<n&&abs(p[2])<n)&&abs(p[1])<=n+1&&abs(p[2])<=n+1;
p=[0, 0]; setb(p); print1(findpos(p[1], p[2]), ", "); p+=move[3, ]; setb(p); forstep(n=1, m-3, 2, my(angmin, jmin, jlast); until(jmin==0, print1(findpos(p[1], p[2]), ", "); angmin=-2*Pi; jmin=0; for(j=1, #move[, 1], my(ptry=p+move[j, ], adiff); if(inring(n, ptry), if(!getb(ptry), adiff=angle(p, ptry); if(adiff<=0, if(adiff>angmin, jmin=j; angmin=adiff; jlast=j))))); if(jmin>0, p+=move[jmin, ]; setb(p); ); ); p+=move[jlast, ]; setb(p)); \\ Hugo Pfoertner, May 11 2019
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Hans Secelle and Albrecht Heeffer (albrecht.heeffer(AT)pandora.be), Mar 09 2002
STATUS
approved