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 81 results. Next

A308080 Index positions of the points with integer coordinates with primary sorting by radius and secondary sorting by polar angle in the counterclockwise square spiral described by A174344 and A274923.

Original entry on oeis.org

1, 2, 4, 6, 8, 3, 5, 7, 9, 11, 15, 19, 23, 12, 14, 16, 18, 20, 22, 24, 10, 13, 17, 21, 25, 28, 34, 40, 46, 29, 33, 35, 39, 41, 45, 47, 27, 30, 32, 36, 38, 42, 44, 48, 26, 53, 61, 69, 77, 54, 60, 62, 68, 70, 76, 78, 52, 31, 37, 43, 49, 55, 59, 63, 67, 71, 75, 79
Offset: 0

Views

Author

Hugo Pfoertner, May 11 2019

Keywords

Comments

The lists of the ring-wise sorted points is provided in A305575 for x and A305576 for y.
The sequence is a permutation of the integers.

Crossrefs

Programs

  • PARI
    /* It is assumed that the files a305575 and a305576 contain the second column of the corresponding b-files omitting the initial 0 */
    a305575=readvec(a305575); a305576=readvec(a305576);
    a174344=vector(10000);L=0; d=1; n=0;
    for(r=1, 100, d=-d; k=floor(r/2)*d; for(j=1, L++, a174344[n++]=k); forstep(j=k-d, -floor((r+1)/2)*d+d, -d, a174344[n++]=j));
    a274923=vector(10100);L=1; d=1;n=0;
    for(r=1, 100, d=-d; k=floor(r/2)*d; for(j=1, L++, a274923[n++]=k); forstep(j=k-d, -floor((r+1)/2)*d+d, -d, a274923[n++]=j));
    findinspiral(i, j)={my(size=(2*max(abs(i), abs(j))+1)^2); forstep(k=size, 1, -1, if(i==a174344[k]&&j==a274923[k], return(k)))};
    print1(findinspiral(0,0),", ");for(n=1,67,print1(findinspiral(a305575[n],a305576[n]),", "));

A308081 Index positions of the points of a counterclockwise square spiral as described by A174344 and A274923 in a list of points with integer coordinates with primary sorting by radius and secondary sorting by polar angle as given by A305575 and A305576.

Original entry on oeis.org

0, 1, 5, 2, 6, 3, 7, 4, 8, 20, 9, 13, 21, 14, 10, 15, 22, 16, 11, 17, 23, 18, 12, 19, 24, 44, 36, 25, 29, 37, 57, 38, 30, 26, 31, 39, 58, 40, 32, 27, 33, 41, 59, 42, 34, 28, 35, 43, 60, 80, 68, 56, 45, 49, 61, 70, 97, 71, 62, 50, 46, 51, 63, 73, 98, 74, 64
Offset: 1

Views

Author

Hugo Pfoertner, May 11 2019

Keywords

Comments

The sequence is a permutation of the integers.

Crossrefs

Programs

  • PARI
    /* It is assumed that the files a305575 and a305576 contain the second column of the corresponding b-files omitting the initial 0 */
    a305575=readvec(a305575); a305576=readvec(a305576);
    a174344=vector(10000); L=0; d=1; n=0;
    for(r=1, 100, d=-d; k=floor(r/2)*d; for(j=1, L++, a174344[n++]=k); forstep(j=k-d, -floor((r+1)/2)*d+d, -d, a174344[n++]=j));
    a274923=vector(10100); L=1; d=1; n=0;
    for(r=1, 100, d=-d; k=floor(r/2)*d; for(j=1, L++, a274923[n++]=k); forstep(j=k-d, -floor((r+1)/2)*d+d, -d, a274923[n++]=j));
    findinring(i, j)={my(s=i*i+j*j);if(s==0,return(0),forstep(k=floor(Pi*(s+1))+sqrtint(s),1,-1,if(i==a305575[k]&&j==a305576[k], return(k))))};
    for(n=1,67,print1(findinring(a174344[n],a274923[n]),", "));

A316667 Squares visited by a knight moving on a spirally numbered board always to the lowest available unvisited square.

Original entry on oeis.org

1, 10, 3, 6, 9, 4, 7, 2, 5, 8, 11, 14, 29, 32, 15, 12, 27, 24, 45, 20, 23, 44, 41, 18, 35, 38, 19, 16, 33, 30, 53, 26, 47, 22, 43, 70, 21, 40, 17, 34, 13, 28, 25, 46, 75, 42, 69, 104, 37, 62, 95, 58, 55, 86, 51, 48, 77, 114, 73, 108, 151, 68, 103, 64, 67, 36
Offset: 1

Views

Author

Daniël Karssen, Jul 10 2018, following a suggestion from N. J. A. Sloane, Jul 09 2018

Keywords

Comments

Board is numbered with the square spiral:
.
17--16--15--14--13 .
| | .
18 5---4---3 12 .
| | | | .
19 6 1---2 11 .
| | | .
20 7---8---9--10 .
| .
21--22--23--24--25--26
.
This sequence is finite: At step 2016, square 2084 is visited, after which there are no unvisited squares within one knight move.

Crossrefs

Cf. A316328 (same starting at 0), A329022 (same with diamond-shaped spiral), A316588 (variant on board with x,y >= 0).
Cf. A326924 (choose square closest to the origin), A328908 (using taxicab distance), A328909 (using sup norm); A323808, A323809.
The (x,y) coordinates of square k are (A174344(k), A274923(k)).

Programs

Formula

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

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

A274640 Counterclockwise square spiral constructed by greedy algorithm, so that each row, column, and diagonal contains distinct numbers.

Original entry on oeis.org

1, 2, 3, 4, 2, 3, 4, 5, 6, 1, 4, 6, 2, 1, 6, 5, 3, 1, 5, 2, 6, 1, 2, 4, 5, 3, 7, 8, 5, 4, 9, 7, 8, 3, 10, 11, 4, 7, 8, 6, 3, 9, 5, 7, 8, 9, 10, 11, 12, 6, 8, 9, 11, 10, 12, 13, 7, 6, 10, 9, 12, 13, 14, 15, 8, 2, 9, 12, 7, 10, 11, 13, 14, 10, 9, 6, 13, 5, 3, 15, 16, 7, 1, 10, 13, 12, 14, 11, 15, 3, 8, 5, 1, 12, 11, 14, 7, 4, 2, 16, 9, 17, 1, 8, 11
Offset: 0

Views

Author

Zak Seidov and Kerry Mitchell, Jun 30 2016

Keywords

Comments

Presumably every row, column, and diagonal is a permutation of the natural numbers, but is there a proof? - N. J. A. Sloane, Jul 10 2016
The n-th cell in the spiral has coordinates x = A174344(n+1), y = A274923(n+1). - N. J. A. Sloane, Jul 11 2016
From Robert G. Wilson v, Dec 25 2016: (Start) [Memo: all these numbers need to decreased by 1, since the offset here is 0. See A324481. - N. J. A. Sloane, Jul 23 2017. Furthermore, the numbers don't seem correct, even after subtracting 1. - N. J. A. Sloane, Jul 04 2019]
Index of first appearance of k = 1,2,3,...: 1, 2, 3, 7, 8, 15, 17, 25, 35, 41, 47, 61, 62, 89, 98, 99, 121, 129, 130, 143, 197, 208, 225, 239, 271, ..., .
1 appears at: 1, 4, 12, 19, 22, 33, 42, 68, 79, 120, 179, 194, 302, 311, 445, 489, 511, 558, 630, 708, 847, 877, 907, ..., .
2 appears at: 2, 5, 9, 16, 48, 52, 70, 73, 88, 95, 110, 146, 280, 291, 309, 327, 488, 605, 656, 681, 735, 778, 1000, ..., .
3 appears at: 3, 6, 10, 23, 29, 36, 56, 76, 97, 105, 153, 168, 184, 252, 338, 437, 457, 670, 818, 906, 953, 967, ..., . (End).

Examples

			The spiral begins:
.
   9--16---2---4---7--14--11--12---1---5---8
   |                                       |
  17   8--15--14--13--12---9--10---6---7   3
   |   |                               |   |
   1   2   4--11--10---3---8---7---9  13  15
   |   |   |                       |   |   |
   8   9   7   3---5---6---1---2   4  12  11
   |   |   |   |               |   |   |   |
  11  12   8   1   2---4---3   6   5  10  14
   |   |   |   |   |       |   |   |   |   |
  15   7   6   5   3   1---2   4   8  11  12
   |   |   |   |   |           |   |   |   |
  14  10   3   2   4---5---6---1   7   9  13
   |   |   |   |                   |   |   |
   7  11   9   6---1---2---4---5---3   8  10
   |   |   |                           |   |
   4  13   5---7---8---9--10--11--12---6   1
   |   |                                   |
  12  14--10---9---6--13---5---3--15--16---7
   |
  10--15---1--12--16---8--14--13--11--18--17
.
The 8 spokes (A274924-A274931) begin:
  E:  1, 2, 4,  8, 11, 12, 16,  9, 19, 24, 22, ...
  NE: 1, 3, 2,  9,  7,  8, 12, 15, 13, 17, 20, ...
  N:  1, 4, 6,  3, 12, 14, 15, 18, 20, 26, 25, ...
  NW: 1, 2, 3,  4,  8,  9,  7, 11, 14, 10, 22, ...
  W:  1, 3, 5,  6,  7, 15, 10, 17, 13, 25, 14, ...
  SW: 1, 4, 6,  5, 14, 10, 11, 23, 16, 18, 21, ...
  S:  1, 5, 2,  9, 13,  8,  7, 11, 10, 17, 19, ...
  SE: 1, 6, 5, 12, 16, 17, 21, 24, 27, 13, 15, ...
		

Crossrefs

Cf. A274641 (the same spiral, but starting with 0 not 1), A174344, A274923.
The 8 spokes are A274924-A274931.
The East-West axis is A275877 (see also A324680), the North-South axis is A276036.
Positions of 1's and 2's give A273059 and A275116.
In the same spirit as the infinite Sudoku array A269526.
Cf. A324481 (position of first n).
Cf. A274821 (the same construction on a hexagonal tiling).

Programs

  • Maple
    #  Maple program from Alois P. Heinz, Jul 12 2016:
    fx:= proc(n) option remember; `if`(n=1, 0, (k->
           fx(n-1)+sin(k*Pi/2))(floor(sqrt(4*(n-2)+1)) mod 4))
         end:
    fy:= proc(n) option remember; `if`(n=1, 0, (k->
           fy(n-1)-cos(k*Pi/2))(floor(sqrt(4*(n-2)+1)) mod 4))
         end:
    b:= proc() 0 end:
    a:= proc(n) local x,y,s,i,t,m;
          x, y:= fx(n+1), fy(n+1);
          if b(x, y) > 0 then b(x, y)
        else s:={};
        for i do t:=b(x+i,y+i); if t>0 then s:=s union {t} else break fi od;
        for i do t:=b(x-i,y-i); if t>0 then s:=s union {t} else break fi od;
        for i do t:=b(x+i,y-i); if t>0 then s:=s union {t} else break fi od;
        for i do t:=b(x-i,y+i); if t>0 then s:=s union {t} else break fi od;
        for i do t:=b(x+i,y  ); if t>0 then s:=s union {t} else break fi od;
        for i do t:=b(x-i,y  ); if t>0 then s:=s union {t} else break fi od;
        for i do t:=b(x  ,y+i); if t>0 then s:=s union {t} else break fi od;
        for i do t:=b(x  ,y-i); if t>0 then s:=s union {t} else break fi od;
             for m while m in s do od;
             b(x,y):= m
          fi
        end:
    seq(a(n), n=0..1000);
  • Mathematica
    fx[n_] := fx[n] = If[n == 1, 0, Function[k, fx[n-1] + Sin[k*Pi/2]][Mod[Floor[Sqrt[4*(n-2)+1]], 4]]]; fy[n_] := fy[n] = If[n == 1, 0, Function[k, fy[n-1] - Cos[k*Pi/2]][Mod[Floor[Sqrt[4*(n-2)+1]], 4]]]; Clear[b]; b[, ] = 0; a[n_] := Module[{x, y, s, i, t, m}, {x, y} = {fx[n+1], fy[n+1]}; If[b[x, y] > 0, b[x, y], s = {};
    For[i=1, True, i++, t=b[x+i, y+i]; If[t>0, s=Union[s,{t}], Break[]]];
    For[i=1, True, i++, t=b[x-i, y-i]; If[t>0, s=Union[s,{t}], Break[]]];
    For[i=1, True, i++, t=b[x+i, y-i]; If[t>0, s=Union[s,{t}], Break[]]];
    For[i=1, True, i++, t=b[x-i, y+i]; If[t>0, s=Union[s,{t}], Break[]]];
    For[i=1, True, i++, t=b[x+i, y  ]; If[t>0, s=Union[s,{t}], Break[]]];
    For[i=1, True, i++, t=b[x-i, y  ]; If[t>0, s=Union[s,{t}], Break[]]];
    For[i=1, True, i++, t=b[x  , y+i]; If[t>0, s=Union[s,{t}], Break[]]];
    For[i=1, True, i++, t=b[x  , y-i]; If[t>0, s=Union[s,{t}], Break[]]];
    m = 1; While[MemberQ[s, m], m++]; b[x, y] = m]]; Table[a[n], {n, 0, 1000}] (* Jean-François Alcover, Nov 14 2016, after Alois P. Heinz *)
  • Python
    class Lines: # manage lines in direction d = dx + dy*1j
        def _init_(self, d):
            self.lines={}; self.t = d.real/d.imag if d.imag else None
        def _call_(self, pos): # Return the line through pos in direction d
            index = pos.imag if self.t is None else pos.real - pos.imag*self.t
            if index not in self.lines: self.lines[index] = Values()
            return self.lines[index]
    class Values(set): # the set of used numbers on a given line
        def next(self, n): # return least k >= n not on this line
            return min(m+1 for m in self if m+1 >= n and m+1 not in self
                       ) if n in self else n
    def A274640(): # generator of the sequence, see below for possible usage
        lines = [Lines(d) for d in (1, 1+1j, 1j, 1-1j)]; pos = 0
        for side in range(9**9):
            for _ in range(side//2 + 1):
                n = 1; lines_here = [L(pos) for L in lines]
                while any(n < (n := L.next(n)) for L in lines_here): pass
                yield n; any(L.add(n) for L in lines_here); pos += 1j**side
    [a for a,A274640(),range(99))%5D%20%23%20_M.%20F.%20Hasler"> in zip(A274640(),range(99))] # _M. F. Hasler, Feb 01 2025

Extensions

Corrected and extended by Alois P. Heinz, Jul 12 2016

A063826 Let 1, 2, 3, 4 represent moves to the right, down, left and up; this sequence describes the movements in the clockwise square spiral (a.k.a. Ulam Spiral).

Original entry on oeis.org

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

Views

Author

Wai Ha Lee (Wainson(AT)hotmail.com), Aug 20 2001

Keywords

Comments

Sequence starts with 1, 2, 3, then can be broken into groups of 8n+4 members, so if n is incremented, starting at 1, the groups follow the following pattern: 3 occurs at the beginning of the group, 4 then occurs 2n times, 1 occurs 2n+1 times, 2 occurs 2n+1 times, 3 occurs 2n+1 times; so each group has 8n+4 terms.
Simpler description: Groups of 2*(2n-1) + 2*(2n) = 8n - 2 terms, n = 1, 2, 3, ..., consisting of 2n-1 times 1, then 2n-1 times 2; then 2n times 3, then 2n times 4. The n-th group starts at index (4n - 6)n + 2 and ends at index (4n + 2)n - 1. - M. F. Hasler, Aug 08 2020

Examples

			Breaking into the groups, we have: 1, 2, 3 n=1: 3, 4, 4, 1, 1, 1, 2, 2, 2, 3, 3, 3, n=2: 3, 4, 4, 4, 4, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3 n=3: 3, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3 and so on.
The spiral of numbers which shows in which order the steps in direction right, down, left and up are made, is depicted for example in sequence A174344. - _M. F. Hasler_, Aug 08 2020
		

Crossrefs

Programs

  • Mathematica
    a[n_] := Mod[Floor[Sqrt[4*n + 1]] + 3, 4] + 1; Table[a[n], {n, 0, 104}] (* Jean-François Alcover, Nov 30 2016 adapted from PARI *)
    Join[{1,2,3},Flatten[Table[{{3},PadRight[{},2n,4],Table[PadRight[{},2n+1,k],{k,3}]},{n,5}]]] (* Harvey P. Dale, Jun 29 2019 *)
  • PARI
    A063826(n)=(sqrtint(4*n+1)+3)%4+1 \\ To see the terms: apply(A063826, [0..99])

Formula

1 <= a(n) <= 4 with a(n) == floor(sqrt(4n + 1)) (mod 4). - M. F. Hasler, Aug 08 2020

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

A214526 Manhattan distances between n and 1 in a square spiral with positive integers and 1 at the center.

Original entry on oeis.org

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

Views

Author

Alex Ratushnyak, Aug 08 2012

Keywords

Comments

Spiral begins:
49 26--27--28--29--30--31
| | |
48 25 10--11--12--13 32
| | | | |
47 24 9 2---3 14 33
| | | | | | |
46 23 8 1 4 15 34
| | | | | |
45 22 7---6---5 16 35
| | | |
44 21--20--19--18--17 36
| |
43--42--41--40--39--38--37

Crossrefs

Programs

  • Mathematica
    f[n_] := Block[{o = 2 n - 1, t, w}, t = Table[0, {o}, {o}]; t = ReplacePart[t, {n, n} -> 1]; Do[w = Partition[Range[(2 (# - 1) - 1)^2 + 1, (2 # - 1)^2], 2 (# - 1)] &@ k; Do[t = ReplacePart[t, {(n + k) - (j + 1), n + (k - 1)} -> #[[1, j]]]; t = ReplacePart[t, {n - (k - 1), (n + k) - (j + 1)} -> #[[2, j]]]; t = ReplacePart[t, {(n - k) + (j + 1), n - (k - 1)} -> #[[3, j]]]; t = ReplacePart[t, {n + (k - 1), (n - k) + (j + 1)} -> #[[4, j]]], {j, 2 (k - 1)}] &@ w, {k, 2, n}]; t]; With[{x = Position[#, 1][[1]]}, Table[Total@ Abs[Position[#, n][[1]] - x], {n, Max@ #}]] &@ f@ 6 (* Michael De Vlieger, Feb 16 2018 *)
  • PARI
    a(n) = n--; my(m=sqrtint(n),k=ceil(m/2)); n=abs(n-4*k^2); k+abs(n-if(n>m,3,1)*k); \\ Kevin Ryde, Oct 25 2019

Formula

abs( a(n) - a(n-1) ) = 1.
For n > 1, a(n) = layer(n) + abs(((n-1) mod (2*layer(n)) - layer(n))) (conjectured) where layer(n) = ceiling(0.5*sqrt(n) - 0.5). - Karl R. Stephan, Jan 26 2018
a(n) = abs(A174344(n)) + abs(A274923(n)). - Kevin Ryde, Oct 25 2019

A296030 Pairs of coordinates for successive integers in the square spiral (counterclockwise).

Original entry on oeis.org

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

Views

Author

Benjamin Mintz, Dec 03 2017

Keywords

Comments

The spiral is also called the Ulam spiral, cf. A174344, A274923 (x and y coordinates). - M. F. Hasler, Oct 20 2019
The n-th positive integer occupies the point whose x- and y-coordinates are represented in the sequence by a(2n-1) and a(2n), respectively. - Robert G. Wilson v, Dec 03 2017
From Robert G. Wilson v, Dec 05 2017: (Start)
The cover of the March 1964 issue of Scientific American (see link) depicts the Ulam Spiral with a heavy black line separating the numbers from their non-sequential neighbors. The pairs of coordinates for the points on this line, assuming it starts at the origin, form this sequence, negated.
The first number which has an abscissa value of k beginning at 0: 1, 2, 10, 26, 50, 82, 122, 170, 226, 290, 362, 442, 530, 626, 730, 842, 962, ...; g.f.: -(x^3 +7x^2 -x +1)/(x-1)^3;
The first number which has an abscissa value of -k beginning at 0: 1, 5, 17, 37, 65, 101, 145, 197, 257, 325, 401, 485, 577, 677, 785, 901, ...; g.f.: -(5x^2 +2x +1)/(x-1)^3;
The first number which has an ordinate value of k beginning at 0: 1, 3, 13, 31, 57, 91, 133, 183, 241, 307, 381, 463, 553, 651, 757, 871, 993, ...; g.f.: -(7x^2+1)/(x-1)^3;
The first number which has an ordinate value of -k beginning at 0: 1, 7, 21, 43, 73, 111, 157, 211, 273, 343, 421, 507, 601, 703, 813, 931, ...; g.f.: -(3x^2+4x+1)/(x-1)^3;
The union of the four sequences above is A033638.
(End)
Sequences A174344, A268038 and A274923 start with the integer 0 at the origin (0,0). One might then prefer offset 0 as to have (a(2n), a(2n+1)) as coordinates of the integer n. - M. F. Hasler, Oct 20 2019
This sequence can be read as an infinite table with 2 columns, where row n gives the x- and y-coordinate of the n-th point on the spiral. If the point at the origin has number 0, then the points with coordinates (n,n), (-n,n), (n,-n) and (n,-n) have numbers given by A002939(n) = 2n(2n-1): (0, 2, 12, 30, ...), A016742(n) = 4n^2: (0, 4, 16, 36, ...), A002943(n) = 2n(2n+1): (0, 6, 20, 42, ...) and A033996(n) = 4n(n+1): (0, 8, 24, 48, ...), respectively. - M. F. Hasler, Nov 02 2019

Examples

			The integer 1 occupies the initial position, so its coordinates are {0,0}; therefore a(1)=0 and a(2)=0.
The integer 2 occupies the position immediately to the right of 1, so its coordinates are {1,0}.
The integer 3 occupies the position immediately above 2, so its coordinates are {1,1}; etc.
		

References

  • S. Wolfram, A New Kind of Science, Wolfram Media, 2002; p. 935.

Crossrefs

Cf. Diagonal rays (+-n,+-n): A002939 (2n(2n-1): 0, 2, 12, 30, ...: NE), A016742 (4n^2: 0, 4, 16, 36, ...: NW), A002943 (2n(2n+1): 0, 6, 20, 42, ...: SW) and A033996 (4n(n+1): 0, 8, 24, 48, ...: SE).

Programs

  • Mathematica
    f[n_] := Block[{k = Ceiling[(Sqrt[n] - 1)/2], m, t}, t = 2k +1; m = t^2; t--; If[n >= m - t, {k -(m - n), -k}, m -= t; If[n >= m - t, {-k, -k +(m - n)}, m -= t; If[n >= m - t, {-k +(m - n), k}, {k, k -(m - n - t)}]]]]; Array[f, 40] // Flatten (* Robert G. Wilson v, Dec 04 2017 *)
    f[n_] := Block[{k = Mod[ Floor[ Sqrt[4 If[OddQ@ n, (n + 1)/2 - 2, (n/2 - 2)] + 1]], 4]}, f[n - 2] + If[OddQ@ n, Sin[k*Pi/2], -Cos[k*Pi/2]]]; f[1] = f[2] = 0; Array[f, 90] (* Robert G. Wilson v, Dec 14 2017 *)
    f[n_] := With[{t = Round@ Sqrt@ n}, 1/2*(-1)^t*({1, -1}(Abs[t^2 - n] - t) + t^2 - n - Mod[t, 2])]; Table[f@ n, {n, 0, 95}] // Flatten (* Mikk Heidemaa May 23 2020, after Stephen Wolfram *)
  • PARI
    apply( {coords(n)=my(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])}, [0..99]) \\ Use concat(%) to remove brackets '[', ']'. This function gives the coordinates of n on the spiral starting with 0 at (0,0), as shown in Examples for A174344, A274923, ..., so (a(2n-1),a(2n)) = coords(n-1). To start with 1 at (0,0), change n to n-=1 in sqrtint(). The inverse function is pos(x,y) given e.g. in A316328. - M. F. Hasler, Oct 20 2019
  • Python
    from math import ceil, sqrt
    def get_coordinate(n):
        k=ceil((sqrt(n)-1)/2)
        t=2*k+1
        m=t**2
        t=t-1
        if n >= m - t:
            return k - (m-n), -k
        else:
            m -= t
        if n >= m - t:
            return -k, -k+(m-n)
        else:
            m -= t
        if n >= m-t:
            return -k+(m-n), k
        else:
            return k, k-(m-n-t)
    

Formula

a(2*n-1) = A174344(n).
a(2*n) = A274923(n) = -A268038(n).
abs(a(n+2) - a(n)) < 2.
a(2*n-1)+a(2*n) = A180714(n).
f(n) = floor(-n/4)*ceiling(-3*n/4 - 1/4) mod 2 + ceiling(n/8) (gives the pairs of coordinates for integers in the diagonal rays). - Mikk Heidemaa, May 07 2020

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
Showing 1-10 of 81 results. Next