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

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

A214176 Sum of the 8 nearest neighbors of n in a spiral with positive integers.

Original entry on oeis.org

44, 58, 72, 62, 96, 82, 120, 94, 104, 152, 120, 130, 184, 146, 144, 164, 224, 180, 176, 198, 264, 214, 208, 216, 240, 312, 256, 248, 256, 282, 360, 298, 288, 296, 304, 332, 416, 348, 336, 344, 352, 382, 472, 398, 384, 392, 400, 408, 440, 536, 456, 440
Offset: 1

Views

Author

Alex Ratushnyak, Jul 06 2012

Keywords

Examples

			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
.
The 8 nearest neighbors of 2 are 1,3,4,8,9,10,11,12. Their sum is a(2)=58.
		

Crossrefs

Cf. A214177 (sum of the 4 nearest neighbors).

Programs

  • Mathematica
    step=15; (f=Join[{12,18,24,6,32,10,40,6},Flatten@Table[{Table[0,k], s=10+2i,56+8i,s},{k,0,step},{i,2k-1,2k}]])+8Range@Length@f+24 (* Giorgos Kalogeropoulos, Sep 23 2023 *)
  • PARI
    \\ See Links section.
  • Python
    SIZE=11  # must be odd
    grid = [0] * (SIZE*SIZE)
    posX = posY = SIZE//2
    grid[posY*SIZE+posX]=1
    n = 2
    saveX = [0]* (SIZE*SIZE+1)
    saveY = [0]* (SIZE*SIZE+1)
    saveX[1]=posX
    saveY[1]=posY
    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 posX+posY==0 or grid[(posY+chkY)*SIZE+posX+chkX]==0:
            return
    while 1:
        walk(0,-1, 1, 0)    # up
        if posX+posY==0:
            break
        walk(1, 0, 0, 1)    # right
        walk(0, 1,-1, 0)    # down
        walk(-1,0, 0,-1)    # left
    for n in range(1,(SIZE-2)*(SIZE-2)+1):
        posX = saveX[n]
        posY = saveY[n]
        k = grid[(posY-1)*SIZE+posX] + grid[(posY+1)*SIZE+posX]
        k+= grid[(posY-1)*SIZE+posX-1] + grid[(posY-1)*SIZE+posX+1]
        k+= grid[(posY+1)*SIZE+posX-1] + grid[(posY+1)*SIZE+posX+1]
        print(k+grid[posY*SIZE+posX-1] + grid[posY*SIZE+posX+1], 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

A215470 Prime intersections in a square spiral with positive integers: primes p such that there are four primes among eight nearest neighbors of p.

Original entry on oeis.org

71, 353, 701, 1151, 1451, 3347, 4691, 13463, 21017, 27947, 34337, 42017, 52253, 57191, 79907, 80831, 81611, 121469, 144497, 159737, 161141, 256301, 265547, 284231, 285707, 312161, 334511, 346559, 348617, 382601, 392069, 422867, 440303, 502013, 541061, 545873, 593207
Offset: 1

Views

Author

Alex Ratushnyak, Aug 11 2012

Keywords

Comments

Conjecture: the sequence is infinite. - Alex Ratushnyak, Sep 19 2012

Examples

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

Crossrefs

Programs

  • Python
    SIZE = 3335  # must be odd
    TOP = SIZE*SIZE
    prime = [1]*TOP
    prime[1]=0
    for i in range(4,TOP,2):
        prime[i]=0
    for i in range(3,TOP,2):
        if prime[i]==1:
            for j in range(i*3,TOP,i*2):
                prime[j]=0
    grid = [0] * TOP
    posX = posY = SIZE//2
    grid[posY*SIZE+posX] = 1
    n = 2
    saveX = [0]* (TOP+1)
    saveY = [0]* (TOP+1)
    saveX[1]=posX
    saveY[1]=posY
    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 posX*posY==0 or grid[(posY+chkY)*SIZE+posX+chkX]==0:
            return
    while 1:
        walk(0, -1, 1, 0)   # up
        if posX*posY==0:
            break
        walk(1, 0, 0, 1)    # right
        walk(0, 1, -1, 0)   # down
        walk(-1, 0, 0, -1)  # left
    for s in range(1, n):
      if prime[s]:
        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])
        if a*b==0 or c*d==0:
            break
        if prime[a]+prime[b]+prime[c]+prime[d]==4:
            print(s, end=', ')

A340459 a(n) is the sum of the numbers adjacent to n in a triangle in which the nonnegative integers are placed from top to bottom and from left to right.

Original entry on oeis.org

3, 9, 10, 18, 26, 23, 31, 44, 50, 40, 48, 68, 74, 80, 61, 69, 98, 104, 110, 116, 86, 94, 134, 140, 146, 152, 158, 115, 123, 176, 182, 188, 194, 200, 206, 148, 156, 224, 230, 236, 242, 248, 254, 260, 185, 193, 278, 284, 290, 296, 302, 308, 314, 320, 226, 234, 338
Offset: 0

Views

Author

Leonardo Sznajder, Jan 10 2021

Keywords

Comments

The triangle of nonnegative integers begins:
0
1 2
3 4 5
6 7 8 9
...

Examples

			For n=4:
- the numbers adjacent to 4 are 1, 2, 3, 5, 7 and 8,
- so a(4) = 1 + 2 + 3 + 5 + 7 + 8 = 26.
		

Crossrefs

Cf. A214177.

Programs

  • Mathematica
    T[i_,j_]:=Binomial[i+1,2]+j; a[i_,j_]:=If[j-1>=0,T[i,j-1],0]+If[i-1>=0&&j-1>=0, T[i-1,j-1],0]+If[i-1>=0&&j<=i-1,T[i-1,j],0]+If[j+1<=i,T[i,j+1],0]+T[i+1,j]+T[i+1,j+1]; Flatten[Table[a[i,j],{i,0,12},{j,0,i}]] (* Stefano Spezia, Jan 28 2021 *)

Extensions

More terms from Stefano Spezia, Jan 28 2021
Showing 1-5 of 5 results.