cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-10 of 22 results. Next

A174344 List of x-coordinates of point moving in clockwise square spiral.

Original entry on oeis.org

0, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -2
Offset: 1

Views

Author

Nikolas Garofil (nikolas(AT)garofil.be), Mar 16 2010

Keywords

Comments

Also, list of x-coordinates of point moving in counterclockwise square spiral.
This spiral, in either direction, is sometimes called the "Ulam spiral", but "square spiral" is a better name. (Ulam looked at the positions of the primes, but of course the spiral itself must be much older.) - N. J. A. Sloane, Jul 17 2018
Graham, Knuth and Patashnik give an exercise and answer on mapping n to square spiral x,y coordinates, and back x,y to n. They start 0 at the origin and first segment North so their y(n) is a(n+1). In their table of sides, it can be convenient to take n-4*k^2 so the ranges split at -m, 0, m. - Kevin Ryde, Sep 16 2019

Examples

			Here is the beginning of the clockwise square spiral. Sequence gives x-coordinate of the n-th point.
.
  20--21--22--23--24--25
   |                   |
  19   6---7---8---9  26
   |   |           |   |
  18   5   0---1  10  27
   |   |       |   |   |
  17   4---3---2  11  28
   |               |   |
  16--15--14--13--12  29
                       |
  35--34--33--32--32--30
.
Given the offset equal to 1, a(n) gives the x-coordinate of the point labeled n-1 in the above drawing. - _M. F. Hasler_, Nov 03 2019
		

References

  • Ronald L. Graham, Donald E. Knuth, Oren Patashnik, Concrete Mathematics, Addison-Wesley, 1989, chapter 3, Integer Functions, exercise 40 page 99 and answer page 498.

Crossrefs

Cf. A180714. A268038 (or A274923) gives sequence of y-coordinates.
The (x,y) coordinates for a point sweeping a quadrant by antidiagonals are (A025581, A002262). - N. J. A. Sloane, Jul 17 2018
See A296030 for the pairs (A174344(n), A274923(n)). - M. F. Hasler, Oct 20 2019
The diagonal rays are: A002939 (2*n*(2*n-1): 0, 2, 12, 30, ...), A016742 = (4n^2: 0, 4, 16, 36, ...), A002943 (2n(2n+1): 0, 6, 20, 42, ...), A033996 = (4n(n+1): 0, 8, 24, 48, ...). - M. F. Hasler, Oct 31 2019

Programs

  • Julia
    function SquareSpiral(len)
        x, y, i, j, N, n, c = 0, 0, 0, 0, 0, 0, 0
        for k in 0:len-1
            print("$x, ") # or print("$y, ") for A268038.
            if n == 0
                c += 1; c > 3 && (c =  0)
                c == 0 && (i = 0; j =  1)
                c == 1 && (i = 1; j =  0)
                c == 2 && (i = 0; j = -1)
                c == 3 && (i = -1; j = 0)
                c in [1, 3] && (N += 1)
                n = N
            end
            n -= 1
            x, y = x + i, y + j
    end end
    SquareSpiral(75) # Peter Luschny, May 05 2019
    
  • Maple
    fx:=proc(n) option remember; local k; if n=1 then 0 else
    k:=floor(sqrt(4*(n-2)+1)) mod 4;
    fx(n-1) + sin(k*Pi/2); fi; end;
    [seq(fx(n),n=1..120)]; # Based on Seppo Mustonen's formula. - N. J. A. Sloane, Jul 11 2016
  • Mathematica
    a[n_]:=a[n]=If[n==0,0,a[n-1]+Sin[Mod[Floor[Sqrt[4*(n-1)+1]],4]*Pi/2]]; Table[a[n],{n,0,50}] (* Seppo Mustonen, Aug 21 2010 *)
  • PARI
    L=0; d=1;
    for(r=1,9,d=-d;k=floor(r/2)*d;for(j=1,L++,print1(k,", "));forstep(j=k-d,-floor((r+1)/2)*d+d,-d,print1(j,", "))) \\ Hugo Pfoertner, Jul 28 2018
    
  • PARI
    a(n) = n--; my(m=sqrtint(n),k=ceil(m/2)); n -= 4*k^2; if(n<0, if(n<-m, k, -k-n), if(nKevin Ryde, Sep 16 2019
    
  • PARI
    apply( A174344(n)={my(m=sqrtint(n-=1), k=m\/2); if(n < 4*k^2-m, k, 0 > n -= 4*k^2, -k-n, n < m, -k, n-3*k)}, [1..99]) \\ M. F. Hasler, Oct 20 2019
    
  • Python
    # Based on Kevin Ryde's PARI script
    import math
    def A174344(n):
        n -= 1
        m = math.isqrt(n)
        k = math.ceil(m/2)
        n -= 4*k*k
        if n < 0: return k if n < -m else -k-n
        return -k if n < m else n-3*k # David Radcliffe, Aug 04 2025

Formula

a(1) = 0, a(n) = a(n-1) + sin(floor(sqrt(4n-7))*Pi/2). For a corresponding formula for the y-coordinate, replace sin with cos. - Seppo Mustonen, Aug 21 2010 with correction by Peter Kagey, Jan 24 2016
a(n) = A010751(A037458(n-1)) for n>1. - William McCarty, Jul 29 2021

Extensions

Link corrected by Seppo Mustonen, Sep 05 2010
Definition clarified by N. J. A. Sloane, Dec 20 2012

A274923 List of y-coordinates of point moving in counterclockwise square spiral.

Original entry on oeis.org

0, 0, 1, 1, 1, 0, -1, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -2, -1, 0
Offset: 1

Views

Author

N. J. A. Sloane, Jul 11 2016

Keywords

Comments

This spiral, in either direction, is sometimes called the "Ulam spiral, but "square spiral" is a better name. (Ulam looked at the positions of the primes, but of course the spiral itself must be much older.) - N. J. A. Sloane, Jul 17 2018
Graham, Knuth and Patashnik give an exercise and answer on mapping n to square spiral x,y coordinates, and back x,y to n. They start 0 at the origin and first segment North so a(n) is their -x(n-1). In their table of sides, it can be convenient to take n-4*k^2 so the ranges split at -m, 0, m. - Kevin Ryde, Sep 17 2019

References

  • Ronald L. Graham, Donald E. Knuth, Oren Patashnik, Concrete Mathematics, Addison-Wesley, 1989, chapter 3, Integer Functions, exercise 40 page 99 and answer page 498.

Crossrefs

Cf. A268038 (negated), A317186 (indices of 0's).
Cf. A174344 (x-coordinates).
The (x,y) coordinates for a point sweeping a quadrant by antidiagonals are (A025581, A002262). - N. J. A. Sloane, Jul 17 2018
A296030 gives pairs (x = A174344(n), y = a(n)). - M. F. Hasler, Oct 20 2019
The diagonal rays of the square spiral (coordinates (+-n,+-n)) are: A002939 (2n(2n-1): 0, 2, 12, 30, ...), A016742 = (4n^2: 0, 4, 16, 36, ...), A002943 (2n(2n+1): 0, 6, 20, 42, ...), A033996 = (4n(n+1): 0, 8, 24, 48, ...). - M. F. Hasler, Oct 31 2019

Programs

  • Maple
    fy:=proc(n) option remember; local k; if n=1 then 0 else
    k:=floor(sqrt(4*(n-2)+1)) mod 4;
    fy(n-1) - cos(k*Pi/2); fi; end;
    [seq(fy(n),n=1..120)]; # Based on Seppo Mustonen's formula in A174344.
  • Mathematica
    a[n_] := a[n] = If[n == 0, 0, a[n-1] - Cos[Mod[Floor[Sqrt[4*(n-1)+1]], 4]* Pi/2]];
    Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Jun 11 2018, after Seppo Mustonen *)
  • PARI
    L=1;d=1;
    for(r=1,9,d=-d;k=floor(r/2)*d;for(j=1,L++,print1(k,", "));forstep(j=k-d,-floor((r+1)/2)*d+d,-d,print1(j,", "))) \\ Hugo Pfoertner, Jul 28 2018
    
  • PARI
    a(n) = n--; my(m=sqrtint(n), k=ceil(m/2)); n -= 4*k^2; if(n<0, if(n<-m, 3*k+n, k), if(nKevin Ryde, Sep 17 2019
    
  • PARI
    apply( A274923(n)={my(m=sqrtint(n-=1), k=m\/2); if(m <= n -= 4*k^2, -k, n >= 0, k-n, n >= -m, k, 3*k+n)}, [1..99]) \\ M. F. Hasler, Oct 20 2019
    
  • Python
    # Based on Kevin Ryde's PARI script
    import math
    def A274923(n):
        n -= 1
        m = math.isqrt(n)
        k = math.ceil(m/2)
        n -= 4*k*k
        if n < 0: return 3*k+n if n < -m else k
        return k-n if n < m else -k # David Radcliffe, Aug 04 2025

A316328 Lexicographically earliest knight's path on spiral on infinite chessboard.

Original entry on oeis.org

0, 9, 2, 5, 8, 3, 6, 1, 4, 7, 10, 13, 28, 31, 14, 11, 26, 23, 44, 19, 22, 43, 40, 17, 34, 37, 18, 15, 32, 29, 52, 25, 46, 21, 42, 69, 20, 39, 16, 33, 12, 27, 24, 45, 74, 41, 68, 103, 36, 61, 94, 57, 54, 85, 50, 47, 76, 113, 72, 107, 150, 67, 102, 63, 66, 35
Offset: 0

Views

Author

N. J. A. Sloane, Jul 13 2018

Keywords

Comments

On a doubly-infinite chessboard, number all the cells in a counterclockwise spiral starting at a central cell labeled 0. Start with a knight at cell 0, and thereafter always move the knight to the smallest unvisited cell. Sequence gives succession of squares visited.
Sequence ends if knight is unable to move.
Inspired by A316588 and, like that sequence, has only finitely many terms; see A316667 for details.
See A326924 for a variant where the knight prefers squares closest to the origin, and gets trapped only after 22325 moves. - M. F. Hasler, Oct 21 2019
See A323809 for an infinite extension of this sequence, obtained by allowing the knight to go back in case it was trapped. See A328908 for a variant of length > 10^6, using the taxicab distance, and A328909 for a variant using the sup norm. - M. F. Hasler, Nov 04 2019

Examples

			The board is spirally numbered, starting with 0 at (0,0), as follows:
.
  16--15--14--13--12   :
   |               |   :
  17   4---3---2  11  28
   |   |       |   |   |
  18   5   0---1  10  27
   |   |           |   |
  19   6---7---8---9  26
   |                   |
  20--21--22--23--24--25
.
Coordinates of a point are given in A174344, A274923 and A296030 (but these have offset 1: they list coordinates of the n-th point on the spiral, so the coordinates of first point, 0 at the origin, have index n = 1, etc).
Starting at the origin, a(0) = 0, the knight jumps to the square with the lowest number at the eight available positions, (+-2, +-1) or (+-1, +-2), which is a(1) = 9 at (2, -1).
From there, the available square with the lowest number is a(2) = 2 at (1, 1): square 0 at the origin is not available since already occupied earlier. Similarly, the knight will not be allowed to go on squares a(1) = 9 or a(2) = 2 ever after.
		

Crossrefs

Cf. A316667 (same with offset 1 and values +1), A316338 (numbers not in this sequence).
Cf. A323809 (infinite extension of this sequence).
Cf. A316588 (variant with diagonally numbered board, coordinates x, y >= 0).
Cf. A326924 and A326922 (variant: choose square closest to the origin), A328908 and A328928 (variant using taxicab distance); A328909 and A328929 (variant using sup norm).
Cf. A326916 and A326918, A326413, A328698 (squares are filled with digits of the infinite word 0,1,...9,1,0,1,1,...).
Cf. A174344, A274923, A296030 (coordinates of a given square).

Programs

  • PARI
    {local( K=[[(-1)^(i\2)<<(i>4),(-1)^i<<(i<5)]|i<-[1..8]], nxt(p, x=coords(p))=vecsort(apply(K->t(x+K), K))[1], pos(x,y)=if(y>=abs(x),4*y^2-y-x,-x>=abs(y),4*x^2-x-y,-y>=abs(x),(4*y-3)*y+x,(4*x-3)*x+y), coords(n, m=sqrtint(n), k=m\/2)=if(m<=n-=4*k^2, [n-3*k, -k], n>=0, [-k, k-n], n>=-m, [-k-n, k], [k, 3*k+n]), U=[], t(x, p=pos(x[1],x[2]))=if(p<=U[1]||setsearch(U, p), oo, p)); my(A=List(0)); for(n=1, oo, U=setunion(U, [A[n]]); while(#U>1&&U[2]==U[1]+1, U=U[^1]); iferr(listput(A, nxt(A[n])), E, break)); print("Index of the last term: ", #A-1); A316328(n)=A[n+1];}

Formula

a(n) = A316667(n+1) - 1.

Extensions

Terms from a(17) on computed by Daniël Karssen, Jul 10 2018
Examples added and crossrefs edited by M. F. Hasler, Nov 04 2019

A326922 Squares visited by a knight moving on a board with squares labeled with their squared distance from the origin and where the knight moves to the smallest labeled unvisited square; the smallest spiral number ordering is used if the distances are equal.

Original entry on oeis.org

0, 5, 2, 1, 2, 1, 2, 1, 2, 1, 4, 5, 10, 13, 4, 5, 10, 5, 10, 5, 4, 13, 10, 5, 10, 13, 4, 5, 10, 13, 16, 13, 10, 5, 16, 13, 20, 9, 8, 9, 8, 9, 8, 9, 8, 17, 18, 17, 26, 25, 20, 25, 10, 13, 16, 29, 18, 17, 26, 25, 20, 25, 20, 13, 16, 29, 18, 17, 26, 25, 20, 25, 40, 41, 34, 37, 50, 29, 18, 17, 26, 25, 20, 25, 20, 25, 26, 37, 34, 25, 26, 17, 34, 25, 26, 17, 34, 25, 20, 37
Offset: 0

Views

Author

Scott R. Shannon, Oct 21 2019

Keywords

Comments

This sequence uses the squared distance from the origin to label the squares. At each step the knight goes to an unvisited square with the smallest label; if there are two or more squares with the same label it then chooses the square with the smallest number if the board was numbered as a spiral, i.e., the smallest spiral numbered square as in A316667.
The sequence is finite. After 22325 steps a square with label 6885 (spiral number = 25984) is visited, after which all neighboring squares have been visited.
If one looks at the spiral number for the visited squares in this sequence one finds it is the same as A316667 for the first 34 steps. On the 35th step this sequence goes to a square with spiral number 77, which is 4 units from the origin, while A316667 goes to square 43, which is sqrt(18) (> 4) units from the origin.
Sequence A326924 gives the number of the square visited at the n-th move, which is at distance^2 a(n) from the origin, cf. formula. - M. F. Hasler, Oct 22 2019

Examples

			The squares are labeled using their squared distance from the origin:
.
    +----+----+----+----+----+----+----+
    | 18 | 13 | 10 |  9 | 10 | 13 | 18 |
    +----+----+----+----+----+----+----+
    | 13 |  8 |  5 |  4 |  5 |  8 | 13 |
    +----+----+----+----+----+----+----+
    | 10 |  5 |  2 |  1 |  2 |  5 | 10 |
    +----+----+----+----+----+----+----+
    |  9 |  4 |  1 |  0 |  1 |  4 |  9 |
    +----+----+----+----+----+----+----+
    | 10 |  5 |  2 |  1 |  2 |  5 | 10 |
    +----+----+----+----+----+----+----+
    | 13 |  8 |  5 |  4 |  5 |  8 | 13 |
    +----+----+----+----+----+----+----+
    | 18 | 13 | 10 |  9 | 10 | 13 | 18 |
    +----+----+----+----+----+----+----+
.
If the knight has a choice of two or more squares with the same label (same squared distance from the origin), then the square with the minimum spiral number, as shown in A316667, is chosen.
		

Crossrefs

Cf. A174344, A274923, A296030 (coordinates of the square number n).

Programs

Formula

a(n) = A174344(A326924(n))^2 + A274923(A326924(n))^2. - M. F. Hasler, Oct 22 2019

A328928 Squares visited by a knight moving on a taxicab geometry numbered board where the knight moves to the smallest numbered unvisited square; the minimum distance from the origin is used if the square numbers are equal; the smallest spiral number ordering is used if the distances are equal.

Original entry on oeis.org

0, 3, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 4, 5, 2, 3, 4, 3, 4, 3, 2, 5, 4, 3, 4, 5, 2, 3, 4, 5, 4, 5, 4, 3, 4, 5, 6, 3, 4, 3, 4, 3, 4, 3, 4, 5, 6, 5, 6, 7, 6, 5, 4, 5, 4, 7, 6, 5, 6, 7, 6, 5, 6, 5, 4, 7, 6, 5, 6, 7, 6, 5, 8, 7, 6, 7, 6, 5, 6, 7, 6, 5, 6, 5, 6, 7, 8, 7, 8, 7, 6, 7, 8, 7, 6, 7, 8, 7, 6
Offset: 0

Views

Author

Scott R. Shannon, Oct 31 2019

Keywords

Comments

This sequence uses the taxicab geometry distance from the 0-squared origin to enumerate each square on the board. At each step the knight goes to an unvisited square with the smallest square number. If the knight has a choice of two or more squares with the same number it then chooses the square which is the closest to the 0-squared origin. If two or more squares are found which also have the same distance to the origin, then the square which was first drawn in a square spiral numbering is chosen, i.e., the smallest spiral numbered square as in A316667.
The sequence is finite. After 1092366 steps a square with the number 728 (standard spiral number = 1165673) is visited, after which all neighboring squares have been visited.
See A328908(n) for the position on the spiral (cf. A316328) of the square visited at move n. - M. F. Hasler, Nov 04 2019

Examples

			The squares are labeled using their taxicab geometry distance from the origin:
.
    +----+----+----+----+----+----+----+
    |  6 |  5 |  4 |  3 |  4 |  5 |  6 |
    +----+----+----+----+----+----+----+
    |  5 |  4 |  3 |  2 |  3 |  4 |  5 |
    +----+----+----+----+----+----+----+
    |  4 |  3 |  2 |  1 |  2 |  3 |  4 |
    +----+----+----+----+----+----+----+
    |  3 |  2 |  1 |  0 |  1 |  2 |  3 |
    +----+----+----+----+----+----+----+
    |  4 |  3 |  2 |  1 |  2 |  3 |  4 |
    +----+----+----+----+----+----+----+
    |  5 |  4 |  3 |  2 |  3 |  4 |  5 |
    +----+----+----+----+----+----+----+
    |  6 |  5 |  4 |  3 |  4 |  5 |  6 |
    +----+----+----+----+----+----+----+
.
If the knight has a choice of two or more squares with the same number which also have the same distance from the origin, then the square with the minimum square spiral number, as shown in A316667, is chosen.
		

Crossrefs

Cf. A174344, A274923, A296030 (coordinates of the n-th point on the spiral).

Programs

Formula

a(n) = |A174344(p)| + |A274923(p)| with p = A328908(n)+1. - M. F. Hasler, Nov 04 2019

A328929 Squares visited by a knight moving on a square-ringed numbered board where the knight moves to the smallest numbered unvisited square; the minimum distance from the origin is used if the square numbers are equal; the smallest spiral number ordering is used if the distances are equal.

Original entry on oeis.org

0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 2, 2, 3, 2, 3, 2, 2, 3, 3, 2, 3, 3, 2, 2, 3, 3, 4, 3, 3, 2, 3, 4, 2, 3, 2, 3, 2, 3, 2, 3, 4, 3, 4, 5, 3, 3, 4, 5, 3, 4, 5, 4, 4, 5, 6, 4, 5, 3, 4, 5, 4, 5, 6, 4, 3, 4, 5, 4, 4, 5, 4, 4, 5, 4, 3, 4, 5, 4, 4, 5, 4, 4, 5, 4, 5, 4, 4, 5, 4, 4, 5, 6, 5, 5, 6
Offset: 0

Views

Author

Scott R. Shannon, Oct 31 2019

Keywords

Comments

This sequence uses the number of the square ring of squares surrounding the 0-numbered origin to enumerate each square on the board. At each step the knight goes to an unvisited square with the smallest square number. If the knight has a choice of two or more squares with the same number it then chooses the square which is the closest to the 0-squared origin. If two or more squares are found which also have the same distance to the origin, then the square which was first drawn in a square spiral numbering is chosen, i.e., the smallest spiral numbered square as in A316667.
The sequence is finite. After 25108 steps a square with the number 73 (standard spiral number = 21041) is visited, after which all neighboring squares have been visited.

Examples

			The squares are labeled using the number of the square ring of squares surrounding the origin:
.
    +---+---+---+---+---+---+---+
    | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
    +---+---+---+---+---+---+---+
    | 3 | 2 | 2 | 2 | 2 | 2 | 3 |
    +---+---+---+---+---+---+---+
    | 3 | 2 | 1 | 1 | 1 | 2 | 3 |
    +---+---+---+---+---+---+---+
    | 3 | 2 | 1 | 0 | 1 | 2 | 3 |
    +---+---+---+---+---+---+---+
    | 3 | 2 | 1 | 1 | 1 | 2 | 3 |
    +---+---+---+---+---+---+---+
    | 3 | 2 | 2 | 2 | 2 | 2 | 3 |
    +---+---+---+---+---+---+---+
    | 3 | 3 | 3 | 3 | 3 | 3 | 3 |
    +---+---+---+---+---+---+---+
.
If the knight has a choice of two or more squares with the same number which also have the same distance from the origin, then the square with the minimum square spiral number, as shown in A316667, is chosen.
		

Crossrefs

Cf. A328909 (number of the visited square, following spiral numbering).
Cf. A326922 (variant using Euclidean or L2-norm), A328928 (variant with 1-norm = taxicab distance); A326924, A328908 (corresponding trajectories, i.e., spiral number of squares).

Programs

Formula

a(n) = max(|A174344(p)|, |A274923(p)|), p = A328908(n)+1. - M. F. Hasler, Nov 04 2019

A328909 Knight's tour on spirally numbered infinite board, when the knight always jumps on the unvisited square closest to the origin, first according to the sup-norm, then 2-norm, then number of the square: a(n) = number of square visited at move n.

Original entry on oeis.org

0, 9, 2, 5, 8, 3, 6, 1, 4, 7, 10, 13, 28, 31, 14, 11, 26, 23, 44, 19, 22, 43, 40, 17, 34, 37, 18, 15, 32, 29, 52, 25, 46, 21, 42, 69, 20, 39, 16, 33, 12, 27, 24, 45, 74, 41, 68, 103, 38, 35, 60, 93, 30, 53, 84, 49, 78, 115, 160, 75, 116, 47, 76, 113, 72, 107, 150, 67, 36, 61, 94, 57, 54, 85, 50, 79, 82
Offset: 0

Views

Author

M. F. Hasler, Oct 31 2019

Keywords

Comments

Differs from A326924 (where only the 2-norm is considered) from a(34) = 42 on, and from A316328 (which considers only the number of the square) from a(48) = 38 on.
When the knight lands on square number a(25108) = 21040 of coordinates (73, -57), there is no unvisited square within reach. The sequence then stops, or can be extended by specifying that the knight has to go back on its path until an unvisited square comes within reach, as in A323809.
The least unvisited square at move 25108 is square number 17822 at (67,67). It is however close to the border of the visited region and the knight will visit it in the infinite extension of the sequence shortly after, at move n = 25358. Is there a square that will never be visited in that infinite extension? (Cf. comments in A323809.) - M. F. Hasler, Nov 04 2019

Examples

			The squares are numbered as in the spiral given in A174344 (upside down to get a counterclockwise spiral, but this is irrelevant here).
The knight starts at a(0) = 0 with coordinates (0, 0).
It jumps to a(1) = 9 with coordinates (2, -1): all 8 available squares (+-2, +-1) and (+-1, +-2) are at the same sup-norm and Euclidean distance from the origin, but square number 9 has the smallest number.
		

Crossrefs

Cf. A328929 for the value on the visited square, sup norm of coordinates of a(n).
Cf. A323809 ~ A316328 ~ A316667, A326924, A328908 (variants).
Cf. A174344, A274923, A296030 (coordinates of square number n).

Programs

  • PARI
    {local(coords(n, m=sqrtint(n), k=m\/2)=if(m<=n-=4*k^2, [n-3*k, -k], n>=0, [-k, k-n], n>=-m, [-k-n, k], [k, 3*k+n]), U=[]/*used squares*/, K=vector(8, i, [(-1)^(i\2)<<(i>4), (-1)^i<<(i<5)])/* knight moves*/, pos(x,y)=if(y>=abs(x), 4*y^2-y-x, -x>=abs(y),4*x^2-x-y, -y>=abs(x),(4*y-3)*y+x, (4*x-3)*x+y), t(x, p=pos(x[1],x[2]))=if(p<=U[1]||setsearch(U, p), oo, [vecmax(abs(x)), norml2(x), p]), nxt(p, x=coords(p))=vecsort(apply(K->t(x+K), K))[1][3]); my(A=List(0)/*list of positions*/); for(n=1, oo, U=setunion(U, [A[n]]); while(#U>1&&U[2]==U[1]+1, U=U[^1]); iferr(listput(A, nxt(A[n])), E, break)); print("Index of last term: ", #A-1); A328909(n)=A[n+1];} \\ To compute the infinite extension of the sequence, set en upper limit to the for() loop and replace "break" by listput(A, A[n-1])

Formula

A328929(n) = max(|A174344(a(n))|, |A274923(a(n))|) = sup norm of the coordinates of square a(n).

A326924 Squares visited by a knight on a spirally numbered board, moving always to the unvisited square closest to the origin.

Original entry on oeis.org

0, 9, 2, 5, 8, 3, 6, 1, 4, 7, 10, 13, 28, 31, 14, 11, 26, 23, 44, 19, 22, 43, 40, 17, 34, 37, 18, 15, 32, 29, 52, 25, 46, 21, 76, 47, 50, 27, 12, 33, 16, 39, 20, 45, 24, 51, 48, 77, 114, 73, 70, 105, 38, 35, 60, 93, 30, 53, 84, 49, 78, 115, 74, 41, 68, 103, 36, 61, 94, 57, 54, 85, 124, 81
Offset: 0

Views

Author

M. F. Hasler, Oct 21 2019

Keywords

Comments

"Closest to the origin" is meant in the sense of Euclidean distance, and in case of a tie, the square coming earliest on the spiral.
Differs from the original A316328 from a(34) = 76 on. See there for more information and other related sequences.
The knight gets trapped at the 22325th move at position (x,y) = (81, -18), from which it can't reach any unvisited square.
Sequence A326922 gives the distance^2 of the square number a(n) visited at move n. - M. F. Hasler, Oct 22 2019
From M. F. Hasler, Nov 04 2019: (Start)
When a(22325) = 25983 at (81, -18) is reached, at distance sqrt(6885) from the origin, the last unvisited square has number 13924, at (-59, 59), distance sqrt(6962) from the origin. This suggests that in an infinite extension (knight moves one step back if no unvisited square is available, cf. A323809) the knight might eventually visit every square. Can this be disproved by a counterexample of a square which will never be visited in the infinite extension? (In A328908 such a counterexample exists even before the knight gets stuck.)
The ratio a(n)/n oscillates between 0.5 and less than 1.7 for all n > 3000, even < 1.5 for all n > 14000, cf. graph of the sequence. What is the superior and inferior limit of this ratio, assuming the infinite extension beyond n = 22325?
(End)

Crossrefs

Cf. A174344, A274923, A296030 (coordinate of square number n).

Programs

  • PARI
    {local(coords(n, m=sqrtint(n), k=m\/2)=if(m<=n-=4*k^2, [n-3*k, -k], n>=0, [-k, k-n], n>=-m, [-k-n, k], [k, 3*k+n]), U=[]/* used squares */, K=vector(8, i, [(-1)^(i\2)<<(i>4), (-1)^i<<(i<5)])/* knight moves */, pos(x,y)=if(y>=abs(x),4*y^2-y-x, -x>=abs(y),4*x^2-x-y, -y>=abs(x),(4*y-3)*y+x, (4*x-3)*x+y), t(x, p=pos(x[1],x[2]))=if(p<=U[1]||setsearch(U, p), oo, [norml2(x),p]), nxt(p, x=coords(p))=vecsort(apply(K->t(x+K), K))[1][2]); my(A=List(0)/*list of positions*/); for(n=1, oo, U=setunion(U, [A[n]]); while(#U>1&&U[2]==U[1]+1, U=U[^1]); iferr(listput(A, nxt(A[n])), E, break)); print("Index of last term: ", #A-1); A326924(n)=A[n+1];} \\ To compute the infinite extension, set upper bound in for() loop and replace "break" by listput(A, A[n-1])

A326918 Squares visited by a knight moving on a single-digit square-spiral numbered board where the knight moves to the smallest numbered unvisited square; the minimum distance from the origin is used if the square numbers are equal; the smallest spiral number ordering is used if the distances are equal.

Original entry on oeis.org

0, 0, 1, 0, 1, 0, 1, 1, 2, 2, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 2, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 2, 2, 1, 1, 0, 2, 3, 2, 2, 1, 3, 1, 1, 1, 2, 2, 3, 2, 3, 1, 4, 3, 5, 6, 1, 1, 1, 1, 1, 3, 1, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 1
Offset: 0

Views

Author

Scott R. Shannon, Oct 21 2019

Keywords

Comments

This sequence uses the same board numbering as A326413, and like that sequence, if the next step encounters two or more squares with the same square number, it then chooses the square which is the closest to the original 0-squared origin. But if two or more squares are found which also have the same distance to the origin, then the square which was first drawn in the spiral numbering is chosen, i.e., the smallest standard spiral numbered square as in A316667.
The sequence is finite. After 1069 steps a square with the number 9 (standard spiral number = 473) is visited, after which all neighboring squares have been visited.
Sequence A326916(n) gives the number of the square visited at step n, i.e., its rank in the spiral, starting with 0, as illustrated, e.g., in A326413. The digit on that square, i.e., a(n) can be obtained through A007376, cf. formula. - M. F. Hasler, Oct 21 2019

Examples

			The squares are numbered using single digits of the spiral number ordering as:
                                .
    2---2---2---1---2---0---2   :
    |                       |   :
    3   1---2---1---1---1   9   3
    |   |               |   |   |
    2   3   4---3---2   0   1   1
    |   |   |       |   |   |   |
    4   1   5   0---1   1   8   3
    |   |   |           |   |   |
    2   4   6---7---8---9   1   0
    |   |                   |   |
    5   1---5---1---6---1---7   3
    |                           |
    2---6---2---7---2---8---2---9
If the knight has a choice of two or more squares in this spiral with the same number which also have the same distance from the origin, then the square with the minimum standard spiral number, as shown in A316667, is chosen.
		

Crossrefs

Cf. A174344, A274923, A296030 (coordinates of the square number n).

Formula

a(n) = A007376(A326916(n)). - M. F. Hasler, Oct 21 2019

A328908 Knight's tour on spirally numbered infinite chessboard, when the knight always jumps on the unvisited square closest to the origin, first according to 1-norm, then 2-norm, then number of the square: a(n) = number of the square visited at the n-th move.

Original entry on oeis.org

0, 9, 2, 5, 8, 3, 6, 1, 4, 7, 10, 13, 28, 31, 14, 11, 26, 23, 44, 19, 22, 43, 40, 17, 34, 37, 18, 15, 32, 29, 52, 25, 46, 21, 76, 47, 50, 27, 12, 33, 16, 39, 20, 45, 24, 51, 48, 77, 114, 73, 70, 105, 38, 35, 60, 93, 30, 53, 84, 49, 78, 115, 74, 41, 68, 103, 36, 61, 94, 57, 54, 85, 124, 175
Offset: 0

Views

Author

M. F. Hasler, Oct 31 2019

Keywords

Comments

Differs from A326924 (where only the 2-norm is considered) from a(73) = 175 on.
The sequence is also finite, when the knight lands on square number a(1092366) there is no unvisited square within reach.
The 1-norm or taxicab distance from the origin of the square a(n) is given in A328928(n).
It appears that this knight's tour would also completely fills the board, if we consider the infinite extension where the knight is allowed to move back on its last step(s) when there's no unvisited square available: no isolated sets of unvisited squares as defined in A323809, seem to occur. Is there a proof or disproof for this? - M. F. Hasler, Nov 04 2019

Examples

			The squares are numbered as in the spiral given in A174344 (upside down to get a counterclockwise spiral, but this is irrelevant here).
The knight starts at a(0) = 0 with coordinates (0, 0).
It jumps to a(1) = 9 with co-ordinates (2, -1): all 8 available squares (+-2, +-1) and (+-1, +-2) are at the same taxicab (2 + 1 = 3) and Euclidean distance (sqrt(2^2 + 1^2) = sqrt(5)) from the origin, but square number 9 has the smallest number.
a(73) = 175 with coordinates (7, 0) is the first destination which is preferred due to the 1-norm (= 7) over A326924(73) = 81 with coordinates (5, -4), having 1-norm 5 + 4 = 9 but Euclidean or 2-norm sqrt(41) smaller than 7.
a(1000) = 816 with coordinates (-10, -14).
a(2000) = 2568 with coordinates (-7, -25).
a(5000) = 4476 with coordinates (21, -33).
a(10000) = 15560 with coordinates (-2, -62).
a(20000) = 19566 with coordinates (-36, 70).
a(50000) = 62092 with coordinates (125, -33).
a(10^5) = 135634 with coordinates (-184, -26), taxicab distance 210 from the origin.
a(200'000) = 259798 with coordinates (47, 255).
a(500'000) = 713534 with coordinates (-68, -422).
a(1'000'000) = 995288 with coordinates (217, 499).
a(1'092'366) = 1165672 with coordinates (188, 540), taxicab norm 728 from the origin, is the last square visited by the knight before there is no unvisited square within reach.
By then the earliest square on the spiral not yet visited is number 629641 at (397, 396), taxicab norm 793, and the unvisited square closest to the origin is number 1794929 at (1, 670), taxicab norm 671.
		

Crossrefs

Cf. A328928 for the "value" (= 1-norm) on the visited square.
Cf. A316328 ~ A316667, A326924, A328909 (variants).
Cf. A174344, A274923, A296030 (coordinates of square number n).

Programs

  • PARI
    {Nmax=1e5;/* Full seq. with > 10^6 terms takes long to compute. */ local( K=[[(-1)^(i\2)<<(i>4),(-1)^i<<(i<5)]|i<-[1..8]], pos(x,y)=if(y>=abs(x),4*y^2-y-x,-x>=abs(y),4*x^2-x-y,-y>=abs(x),(4*y-3)*y+x,(4*x-3)*x+y), coords(n, m=sqrtint(n), k=m\/2)=if(m<=n-=4*k^2, [n-3*k, -k], n>=0, [-k, k-n], n>=-m, [-k-n, k], [k, 3*k+n]), t(x, p=pos(x[1],x[2]))=if(pt(x+K), K))[1][3], U=0,Umin=0); my(A=List(0)); for(n=1, Nmax, U+=1<<(A[n]-Umin); while(bittest(U,0), U>>=1;Umin++); iferr(listput(A, nxt(A[n])), E, break)); print("Index of the last term: ", #A-1); A328908(n)=A[n+1];}

Formula

A328928(n) = |A174344(a(n))| + |A274923(a(n))|, the 1-norm (or taxicab distance) of the square visited at the n-th step.
Showing 1-10 of 22 results. Next