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-8 of 8 results.

A010751 Up once, down twice, up three times, down four times, ...

Original entry on oeis.org

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

Views

Author

David Berends (dave(AT)pgt.com)

Keywords

Comments

Also x-coordinates of a point moving in a spiral rotated by Pi/4, with y-coordinates given by A305258. - Hugo Pfoertner, May 29 2018
This sequence is also obtained by reading alternately in ascending or descending way the antidiagonals of the array defined as A(i, j) = floor((j - i + 1)/2) (see Example). - Stefano Spezia, Jan 02 2022

Examples

			From _Stefano Spezia_, Jan 02 2022: (Start)
The array A begins with:
   0   1   1   2   2   3   3 ...
   0   0   1   1   2   2   3 ...
  -1   0   0   1   1   2   2 ...
  -1  -1   0   0   1   1   2 ...
  -2  -1  -1   0   0   1   1 ...
  -2  -2  -1  -1   0   0   1 ...
  ...
(End)
		

Crossrefs

Programs

  • Mathematica
    n=(the index); x = -1; y = 0; While[n != 0, While[y != x && n != 0, y--; n-- ]; While[y != -x && n != 0, n--; y++ ]; x-- ]; Print[ -y] (* provided by Gregory Puleo *)
    n = (the index); a = Floor[(-1 - Sqrt[1 + 8* n])/4]; b = -Floor[(1 - Sqrt[1 + 8*n])/4]; a + 1 - Sign[a*(2*a + 1) - b*(2*b + 1)]*(n - 2*a^2 - 3*a - 1) (* Mark Spindler, Mar 25 2004 *)
  • PARI
    step=-1;print1(x=0,", ");for(stride=1,12,step=-step;for(k=1,stride,print1(x+=step,", "))) \\ Hugo Pfoertner, Jun 02 2018
    
  • Python
    from math import isqrt
    def A010751(n): return n-(m**2>>1) if (m:=isqrt(n+1<<3)+1>>1)&1 else (m**2>>1)-n # Chai Wah Wu, Jun 08 2025

Formula

a(n) = x + 1 - (sign(x(2x+1) - y(2y+1)))*(n-2x^2-3x-1) where x = floor((-1-sqrt(1+8n))/4), y = -floor((1-sqrt(1+8n))/4), sign(x) = abs(x)/x when x is not 0 and sign(0) = 0, floor(x) is the greatest integer less than or equal to x, sqrt(x) is the principal square root of x and abs(x) is the absolute value (or magnitude) of x. - Mark Spindler, Mar 25 2004
From David A. Corneth, Jun 02 2018: (Start)
a(A007590(k)) = a(floor(k^2 / 2)) = 0.
a(A000384(k)) = a(binomial(2 * k, 2)) = k, a new maximum so far.
a(A014105(k)) = a(binomial(2 * k + 1, 2)) = -k, a new minimum so far.
(End)
a(n) = (-1)^A002024(n+1)*(A007590(A002024(n+1))-n). - William McCarty, Jul 30 2021

A053616 Pyramidal sequence: distance to nearest triangular number.

Original entry on oeis.org

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

Views

Author

Henry Bottomley, Mar 20 2000

Keywords

Comments

From Wolfdieter Lang, Oct 24 2020: (Start)
If this sequence is written with offset 1 as a number triangle T(n, k), with n the length of row n, for n >= 1, then row n gives the primitive period of the periodic sequence {k (mod* n)}_{k>=0}, where k (mod* n) = k (mod n) if k <= floor(n/2) and otherwise it is -k (mod n). Such a modified modular relation mod* n has been used by Brändli and Beyne, but for integers relative prime to n.
These periodic sequences are given in A000007, A000035, A011655, A007877, |A117444|, A260686, A279316, for n = 1, 2, ..., 7. For n = 10 A271751, n = 12 A271832, n = 14 A279313. (End)

Examples

			a(12) = |12 - 10| = 2 since 10 is the nearest triangular number to 12.
From _M. F. Hasler_, Dec 06 2019: (Start)
Ignoring a(0) = 0, the sequence can be written as triangle indexed by m >= k >= 1, in which case the terms are (m - |k - |m-k||)/2, as follows:
   0,      (Row 0: ignore)
   0,      (Row m=1, k=1: For k=m, m - |k - |m-k|| = m - |m - 0| = 0.)
   1, 0,        (Row m=2: for k=1, |m-k| = 1, k-|m-k| = 0, m-0 = 2, (...)/2 = 1.)
   1, 1, 0,
   1, 2, 1, 0,    (Row m=4: for k=2, we have twice the value of (m=2, k=1) => 2.)
   1, 2, 2, 1, 0,
   (...)
This is related to the non-associative operation A049581(x,y) = |x - y| =: x @ y. Specifically, @ is commutative and any x is its own inverse, so non-associativity of @ can be measured through the commutator ((x @ y) @ y) @ x which equals twice the element indexed {m,k} = {x,y} in the above triangle.
(End)
		

Crossrefs

a(n) = abs(A305258(n)).

Programs

  • Mathematica
    a[n_] := (k =.; k = Reduce[k > 0 && k*(k+1)/2 == n, Reals][[2]] // Floor; Min[(k+1)*(k+2)/2 - n, n - k*(k+1)/2]); Table[a[n], {n, 0, 104}] (* Jean-François Alcover, Jan 08 2013 *)
    Module[{trms=120,t},t=Accumulate[Range[Ceiling[(Sqrt[8*trms+1]-1)/2]]]; Join[{0},Flatten[Table[Abs[Nearest[t,n][[1]]-n],{n,trms}]]]] (* Harvey P. Dale, Nov 08 2013 *)
  • PARI
    print1(x=0, ", ");for(stride=1,13,x+=stride;y=x+stride+1;for(k=x,y-1,print1(min(k-x,y-k), ", "))) \\ Hugo Pfoertner, Jun 02 2018
    
  • PARI
    apply( {a(n)=if(n,-abs(n*2-(n=sqrtint(8*n-7)\/2)^2)+n)\2}, [0..40]) \\ same as (i - |j - |i-j||)/2 with i=sqrtint(8*n-7)\/2, j=n-i(i-1)/2. - M. F. Hasler, Dec 06 2019
    
  • Python
    from math import isqrt
    def A053616(n): return abs((m:=isqrt(k:=n<<1))*(m+1)-k)>>1 # Chai Wah Wu, Jul 15 2022

Formula

a(n) = (x - |y - |x-y||)/2, when (x,y) is the n-th element in the triangle x >= y >= 1. - M. F. Hasler, Dec 06 2019
a(n) = (1/2)*abs(t^2 + t - 2*n), where t = floor(sqrt(2*n)) = A172471. - Ridouane Oudra, Dec 15 2021
From Ctibor O. Zizka, Nov 12 2024: (Start)
For s >= 1, t from [0, s] :
a(2*s^2 + t) = s - t.
a(2*s^2 - t) = s - t.
a(2*s^2 + 2*s - t) = s - t.
a(2*s^2 + 2*s + 1 + t) = s - t. (End)

A215468 Sum of the 8 nearest neighbors of n in a rotated-square spiral with positive integers.

Original entry on oeis.org

50, 62, 72, 86, 76, 84, 122, 88, 144, 104, 166, 120, 152, 160, 144, 218, 160, 168, 248, 184, 192, 278, 208, 216, 260, 268, 240, 248, 346, 264, 272, 280, 384, 296, 304, 312, 422, 328, 336, 344, 400, 408, 368, 376, 384, 506, 400, 408, 416, 424, 552, 440, 448, 456, 464, 598
Offset: 1

Views

Author

Alex Ratushnyak, Aug 11 2012

Keywords

Examples

			Spiral begins:
                     85
                     /
                    /
                  84 61-62
                  /  /    \
                 /  /      \
               83 60 41-42 63
               /  /  /    \  \
              /  /  /      \  \
            82 59 40 25-26 43 64
            /  /  /  /    \  \  \
           /  /  /  /      \  \  \
         81 58 39 24 13-14 27 44 65
         /  /  /  /  /    \  \  \  \
        /  /  /  /  /      \  \  \  \
      80 57 38 23 12  5--6 15 28 45 66
      /  /  /  /  /  /    \  \  \  \  \
     /  /  /  /  /  /      \  \  \  \  \
   79 56 37 22 11  4  1--2  7 16 29 46 67
     \  \  \  \  \  \   /  /  /  /  /  /
      \  \  \  \  \  \ /  /  /  /  /  /
      78 55 36 21 10  3  8 17 30 47 68
        \  \  \  \  \   /  /  /  /  /
         \  \  \  \  \ /  /  /  /  /
         77 54 35 20  9 18 31 48 69
           \  \  \  \   /  /  /  /
            \  \  \  \ /  /  /  /
            76 53 34 19 32 49 70
              \  \  \   /  /  /
               \  \  \ /  /  /
               75 52 33 50 71
                 \  \   /  /
                  \  \ /  /
                  74 51 72
                    \   /
                     \ /
                     73
.
The 8 nearest neighbors of 4 are 1,3,5,10,11,12,21,23, their sum is 86, so a(4)=86.
		

Crossrefs

Coordinates (but 0-based): A010751, A305258.

Programs

  • Python
    SIZE=17  # must be odd
    grid = [0] * (SIZE*SIZE)
    posX = posY = SIZE//2
    saveX = [0]* (SIZE*SIZE+1)
    saveY = [0]* (SIZE*SIZE+1)
    grid[posY*SIZE+posX]=1
    saveX[1]=posX
    saveY[1]=posY
    posX += 1
    grid[posY*SIZE+posX]=2
    saveX[2]=posX
    saveY[2]=posY
    n = 3
    def walk(stepX, stepY, chkX, chkY):
      global posX, posY, n
      while 1:
        posX+=stepX
        posY+=stepY
        grid[posY*SIZE+posX]=n
        saveX[n]=posX
        saveY[n]=posY
        n+=1
        if grid[(posY+chkY)*SIZE+posX+chkX]==0:
            return
    while posX!=SIZE-1:
        walk(-1,  1, -1, -1)    # down-left
        walk(-1, -1,  1, -1)    # up-left
        walk( 1, -1,  1,  0)    # up-right
        walk( 1,  0,  1,  1)    # right
        walk( 1,  1, -1,  1)    # down-right
    for s in range(1, n):
        posX = saveX[s]
        posY = saveY[s]
        i,j = grid[(posY-1)*SIZE+posX-1], grid[(posY-1)*SIZE+posX+1]
        u,v = grid[(posY+1)*SIZE+posX-1], grid[(posY+1)*SIZE+posX+1]
        if i==0 or j==0 or u==0 or v==0:
            break
        k = grid[(posY-1)*SIZE+posX  ] + grid[(posY+1)*SIZE+posX  ]
        k+= grid[ posY   *SIZE+posX-1] + grid[ posY   *SIZE+posX+1]
        print(i+j+u+v+k, end=' ')
    print()
    for y in range(SIZE):
        for x in range(SIZE):
            print('%3d' % grid[y*SIZE+x], end=' ')
        print()
    
  • Python
    def spiral(x, y):
        r = abs(x) + abs(y)
        return 1 + 2*r*r + (y-r if x > 0 else r-y)
    def A215468(n):
        x = A010751(n-1)
        y = A305258(n-1)
        return sum(spiral(x+i, y+j) for i in (-1, 0, 1) for j in (-1, 0, 1)
                   if (i, j) != (0, 0)) # David Radcliffe, Aug 05 2025

A215471 Numbers k such that in a rotated-square spiral with positive integers (A215468) among k's eight nearest neighbors five or more are primes.

Original entry on oeis.org

8, 30, 138, 658, 2620, 3010, 3168, 3372, 3462, 8628, 11940, 17682, 24918, 27918, 32560, 39228, 39790, 40128, 43608, 48532, 53268, 55372, 56040, 56712, 73362, 85200, 85888, 90646, 96052, 101748, 102652, 104382, 112068, 113932, 115330, 119298, 128518, 129288, 131500
Offset: 1

Views

Author

Alex Ratushnyak, Aug 11 2012

Keywords

Examples

			Spiral begins:
                            113
                        112  85  86
                    111  84  61  62  87
                110  83  60  41  42  63  88
            109  82  59  40  25  26  43  64  89
        108  81  58  39  24  13  14  27  44  65  90
    107  80  57  38  23  12   5   6  15  28  45  66  91
106  79  56  37  22  11   4   1   2   7  16  29  46  67  92
    105  78  55  36  21  10   3   8  17  30  47  68  93
        104  77  54  35  20   9  18  31  48  69  94
            103  76  53  34  19  32  49  70  95
                102  75  52  33  50  71  96
                    101  74  51  72  97
                        100  73  98
                             99
Among eight nearest neighbors of 30 five are primes: 7, 17, 31, 29, 47.
		

Crossrefs

Programs

  • Python
    SIZE = 3335  # must be odd
    TOP = SIZE*SIZE
    t = TOP//2
    prime = [1]*t
    prime[1]=0
    for i in range(4,t,2):
        prime[i]=0
    for i in range(3,t,2):
        if prime[i]==1:
            for j in range(i*3,t,i*2):
                prime[j]=0
    grid = [0] * TOP
    posX = posY = SIZE//2
    saveX = [0]* (t+1)
    saveY = [0]* (t+1)
    grid[posY*SIZE+posX] = 1
    saveX[1]=posX
    saveY[1]=posY
    posX += 1
    grid[posY*SIZE+posX] = 2
    saveX[2]=posX
    saveY[2]=posY
    n = 3
    def walk(stepX, stepY, chkX, chkY):
      global posX, posY, n
      while 1:
        posX+=stepX
        posY+=stepY
        grid[posY*SIZE+posX]=n
        saveX[n]=posX
        saveY[n]=posY
        n+=1
        if grid[(posY+chkY)*SIZE+posX+chkX]==0:
            return
    while posX!=SIZE-1:
        walk(-1,  1, -1, -1)    # down-left
        walk(-1, -1,  1, -1)    # up-left
        walk( 1, -1,  1,  0)    # up-right
        walk( 1,  0,  1,  1)    # right
        walk( 1,  1, -1,  1)    # down-right
    for s in range(1, n):
        posX = saveX[s]
        posY = saveY[s]
        a,b=(grid[(posY-1)*SIZE+posX-1]) , (grid[(posY-1)*SIZE+posX+1])
        c,d=(grid[(posY+1)*SIZE+posX-1]) , (grid[(posY+1)*SIZE+posX+1])
        e,f=(grid[(posY-1)*SIZE+posX  ]) , (grid[(posY+1)*SIZE+posX  ])
        g,h=(grid[ posY   *SIZE+posX-1]) , (grid[ posY   *SIZE+posX+1])
        if a*b==0 or c*d==0 or e*f==0 or g*h==0:
            break
        z = prime[a]+prime[b]+prime[c]+prime[d]
        if z+prime[e]+prime[f]+prime[g]+prime[h] >= 5:
            print(s, end=' ')
    
  • Python
    # See A215468 for the definition of spiral().
    from sympy import isprime
    def neighbors(n):
        x = A010751(n-1)
        y = A305258(n-1)
        return [spiral(x+i, y+j) for i in (-1, 0, 1) for j in (-1, 0, 1) if (i, j) != (0, 0)]
    def is_A215471(n): return sum(map(isprime, neighbors(n))) >= 5 # David Radcliffe, Aug 05 2025

A329022 Squares visited by a knight moving on a diagonal spiral numbered board and moving to the lowest available unvisited square at each step.

Original entry on oeis.org

1, 14, 7, 3, 6, 4, 8, 5, 10, 2, 9, 17, 28, 43, 13, 15, 26, 24, 11, 20, 32, 48, 29, 44, 63, 25, 12, 21, 34, 18, 30, 45, 27, 16, 31, 19, 35, 22, 39, 57, 36, 23, 37, 54, 75, 51, 71, 95, 68, 91, 65, 46, 69, 49, 33, 53, 74, 50, 70, 47, 66, 89, 116, 42, 40, 58, 80, 55, 38, 56, 77, 102, 131, 52, 72, 96, 124
Offset: 1

Views

Author

Scott R. Shannon, Nov 02 2019

Keywords

Comments

This sequence uses a diagonal spiral of numbers to enumerate the squares on the board. The knight starts on the square with number 1. At each step the knight goes to an unvisited square with the smallest number.
The sequence if finite. After 3722 steps the square with number 3541 is visited, after which all neighboring squares have been visited.

Examples

			The board is numbered in a spiral moving along the diagonals of the square grid:
.
                       19
                     /   \
                   /       \
                 20    9     18
               /     /   \     \
             /     /       \     \
           21    10    3     8     17
         /     /     /   \     \     \
       /     /     /       \     \     \
     22    11    4     1 --- 2     7     16
       \     \     \             /     /     .
         \     \     \         /     /     .
           23    12    5 --- 6     15    28
             \     \             /     /
               \     \         /     /
                 24    13 -- 14    27
                   \             /
                     \         /
                       25 -- 26
.
    +----+----+----+----+----+----+----+
    | 76 | 53 | 34 | 19 | 32 | 49 | 70 |
    +----+----+----+----+----+----+----+
    | 54 | 35 | 20 |  9 | 18 | 31 | 48 |
    +----+----+----+----+----+----+----+
    | 36 | 21 | 10 |  3 |  8 | 17 | 30 |
    +----+----+----+----+----+----+----+
    | 22 | 11 |  4 |  1 |  2 |  7 | 16 |
    +----+----+----+----+----+----+----+
    | 38 | 23 | 12 |  5 |  6 | 15 | 28 |
    +----+----+----+----+----+----+----+
    | 58 | 39 | 24 | 13 | 14 | 27 | 44 |
    +----+----+----+----+----+----+----+
    | 82 | 59 | 40 | 25 | 26 | 43 | 64 |
    +----+----+----+----+----+----+----+
.
		

Crossrefs

Cf. A316667.
Cf. A010751(n), A305258(n) for coordinates of point number n+1.

A337822 Permutation of the natural numbers formed by numbering an infinite square grid by a counterclockwise diamond spiral and visiting them by a counterclockwise stair step spiral.

Original entry on oeis.org

1, 2, 8, 3, 9, 20, 10, 21, 11, 4, 12, 5, 13, 14, 6, 15, 7, 16, 30, 17, 31, 18, 32, 19, 33, 52, 34, 53, 35, 54, 36, 55, 37, 22, 38, 23, 39, 24, 40, 25, 41, 42, 26, 43, 27, 44, 28, 45, 29, 46, 68, 47, 69, 48, 70, 49, 71, 50, 72, 51, 73, 100, 74, 101, 75, 102, 76
Offset: 1

Views

Author

Mohammed Yaseen, Sep 24 2020

Keywords

Examples

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

Crossrefs

Cf. A102083.
Diamond spiral coordinates (but 0-based): A010751, A305258.
Same type of visit on other types of spirals: A334619, A337838.

Formula

a(A102083(n)) = A102083(n) and a(A102083(n)+1) = A102083(n)+1.

A383184 Diamond spiral numbers of the grid points visited by a king always moving to the unvisited point labeled with the smallest possible prime or else composite number.

Original entry on oeis.org

0, 2, 3, 11, 23, 4, 5, 13, 12, 24, 41, 61, 40, 59, 83, 60, 84, 113, 85, 86, 62, 25, 26, 43, 14, 1, 7, 17, 31, 8, 19, 9, 10, 37, 21, 20, 53, 34, 33, 18, 32, 71, 97, 127, 72, 73, 50, 49, 48, 47, 29, 6, 15, 16, 30, 69, 68, 67, 28, 27, 44, 89, 64, 63, 42, 87, 88, 149, 116, 115, 114, 146, 223, 182, 181, 144, 179, 112, 111, 110, 109, 58, 38, 22, 57, 56, 79, 107, 139, 80, 81, 82, 39
Offset: 0

Views

Author

M. F. Hasler, May 13 2025

Keywords

Comments

The infinite 2D grid is labeled along a diamond spiral as shown in A305258, starting with 0 at the origin (0,0), where each "shell" contains the points with given taxicab or L1-norm, as follows:
. (y)
2 | 8 17
| / \ \
1 | 9 2 7 16
| / / \ \ \
0 | 10 3 0--1 6 15
| \ \ / /
-1 | 11 4--5 14
| \ /
-2 | 12--13
x: -2 -1 0 1 2 3
.
(This numbering, where the n-th "shell" has only 4n numbers, is "finer" than the square spiral numbering where the n-th shell has 8n numbers.)
The cursor is moving like a chess king to the von Neumann neighbor not visited earlier and labeled with the smallest prime number if possible, otherwise with the smallest possible composite number.
After the 92th move, the cursor is trapped in the point (-1,-3) labeled a(92) = 39. All eight neighbors were then already visited earlier, so the king has no more any possible move: see the "path plot" given in the links section.

Examples

			From the starting point (0,0) labeled a(0) = 0, the king can reach the point (0,1) labeled 2, which is the smallest possible prime number, so a(1) = 2.
Then the king can reach (-1,0) labeled 3 which is the next smaller prime number, so a(2) = 3. From there it can go to (-1,-1) labeled 11 = a(3), and so on.
The king reaches (1,7) and (1,-9) before getting trapped at (-1,-3) from where there is no more any unvisited point among the 8 neighbors.
		

Crossrefs

Cf. A383183 (same with square spiral numbering).
Cf. A305258 (more details about the diamond spiral).

Programs

  • Python
    from sympy import isprime
    def diamond_number(z):
        x, y = int(z.real), int(z.imag); d = abs(x)+abs(y)
        return 2*d*(d-1)+((x if y<0 else d+y)if x>0 else 2*d-x if y>0 else 3*d-y)
    def A383184(n, moves=(1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j)):
        if not hasattr(A:=A383184, 'terms'): A.terms=[0]; A.pos=0; A.path=[0]
        while len(A.terms) <= n:
            try: _,s,z = min((1-isprime(s), s, z) for d in moves if
                             (s := diamond_number(z := A.pos+d))not in A.terms)
            except ValueError:
                raise IndexError(f"Sequence has only {len(A.terms)} terms")
            A.terms.append(s); A.pos = z; A.path.append(z)
        return A.terms[n]
    A383184(999) # gives IndexError: Sequence has only 93 terms
    A383184.terms # shows the full sequence
    import matplotlib.pyplot as plt # this and following to plot the path:
    plt.plot([z.real for z in A383184.path], [z.imag for z in A383184.path])
    plt.show()

A383187 Diamond spiral number of the n-th point visited by the king moving on the two-dimensional grid always to the earliest unvisited point on the spiral, not immediately preceding or following on the spiral.

Original entry on oeis.org

0, 2, 7, 1, 4, 11, 3, 9, 19, 8, 17, 30, 16, 6, 14, 5, 12, 23, 38, 22, 10, 20, 34, 52, 33, 18, 31, 48, 69, 47, 29, 15, 27, 43, 26, 13, 24, 39, 58, 81, 57, 37, 21, 35, 53, 75, 101, 74, 51, 32, 49, 70, 95, 124, 94, 68, 46, 28, 44, 64, 88, 63, 42, 25, 40, 59, 82, 109, 140, 108, 80, 56, 36, 54, 76
Offset: 0

Views

Author

M. F. Hasler, May 12 2025

Keywords

Comments

A permutation of the nonnegative integers, whose restriction to the positive integers is also a permutation. See A383189 for the inverse permutation.
By "king" we simply mean a cursor that can move to any of the 8 nearest (von Neumann) neighbors, as the king moves in the game of chess.
Analog of A383185 (which uses the square spiral or shells of given sup norm) for the diamond spiral (or shells of given taxicab or L1-norm) as defined, e.g., in A305258. There are less grid points having a given L1 norm, so, in this sense, the diamond spiral numbering yields a "finer" measure of the distance from the origin than the square spiral numbering.
Instead of introducing a wall that has to be crossed (as in A383185), it is here sufficient to forbid the immediately following or preceding point in order to avoid a trivial sequence (0, 1, 2, ...) of numbers.
The actual trajectory of the king is however relatively uninteresting: The resulting path consists in a clockwise square spiral (centered at (1/2, 1/2)) with transition to the next shell on the negative y-axis, cf. the "path plot" given in links.

Crossrefs

Cf. A305258 (diamond spiral), A383185 (similar for a square spiral).
Cf. A383189 (inverse permutation).

Programs

  • Python
    def diamond_number(z):
        x, y = int(z.real), int(z.imag); d = abs(x)+abs(y)
        return 2*d*(d-1)+((x if y<0 else d+y)if x>0 else 2*d-x if y>0 else 3*d-y)
    def A383187(n):
        if not hasattr(A:=A383187, 'terms'): A.terms=[0]; A.pos=0; # A.track=[0]
        while len(A.terms) <= n:
            s, d = min((s, d) for d in (1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j) if
                abs((s:=diamond_number(A.pos+d))-A.terms[-1]) > 1 and s not in A.terms)
            A.terms.append(s); A.pos += d; # A.track.append(A.pos)
        return A.terms[n]
Showing 1-8 of 8 results.