login
A306659
x-coordinates of a counterclockwise knight's tour on an infinite board starting at the origin and then successively visiting fields in concentric rings of width 2. y-coordinates are in A306660.
3
0, 2, 0, -2, -1, 1, 2, 1, -1, -2, 0, 2, 1, -1, -2, -1, 1, 0, -2, -1, -2, 0, 2, 1, 2, 3, 1, -1, -3, -4, -3, -4, -2, 0, 2, 4, 3, 4, 3, 1, -1, -3, -4, -3, -4, -3, -1, 1, 3, 4, 3, 4, 2, 0, -2, -4, -3, -4, -3, -1, 1, 3, 4, 3, 4, 2, 0, -2, -4, -3, -4, -3, -4, -2, 0
OFFSET
1,2
COMMENTS
The tour starts with a prescribed initial move (0,0) -> (2,1). It then proceeds to the next field (x,y) not yet visited, satisfying the "ring" conditions
!(abs(x) < liminn and abs(y) < liminn) and abs(x) <= limout and abs(y) <= limout, with liminn=1, limout=2 in the first round, liminn=3, limout=4 in the second round, liminn=5, limout=6 in the third round, ...
Each move is selected from the list of the 8 possible moves, such that the angular difference between the polar angles of the starting point and the target point achieves the minimum of the available positive values. This guarantees the counterclockwise advancing of the tour.
When all fields inside a ring have been visited, an extension step continuing the last used direction inside the preceding inner ring is performed, thus establishing the first visited field in the next ring.
The selection method continues by successively visiting fields in the current ring until no more free fields are available.
A similar method of construction is used in A068608 and its 7 companion sequences. In contrast to the present sequence, initial steps are chosen such that the extension steps are parallel to the initial step. Clockwise advancement is used in A068608-A068611, counterclockwise advancement is used in A068612-A068615. The tour's visited fields are then mapped to a clockwise square number spiral starting with number 1 for the origin and first step to (0,1).
LINKS
Jay Warendorff, An Infinite Knight's Tour, Wolfram Demonstrations Project, March 7 2011.
PROG
(PARI) 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; \\ Extension of board - 2
b=matrix(2*m+1, 2*m+1, i, j, 0); \\ Visited fields
ptarget=1; \\ change to 2 to print A306660
setb(pos)={b[pos[1]+m+1, pos[2]+m+1]=1}; \\ Mark visited fields
getb(pos)=b[pos[1]+m+1, pos[2]+m+1]; \\ Check visited fields
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(p[ptarget], ", "); p+=move[1, ]; setb(p); forstep(n=1, m-3, 2, my(angmin, jmin, jlast); until(jmin==0, print1(p[ptarget], ", "); 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));
KEYWORD
sign
AUTHOR
Hugo Pfoertner, May 05 2019
STATUS
approved