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.

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

A337116 Spiral on a 2D square lattice, one term per cell, starting at the origin with 0; the four integers forming any 2 X 2 square add up to a prime.

Original entry on oeis.org

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

Views

Author

Eric Angelini and Jean-Marc Falcoz, Aug 16 2020

Keywords

Comments

This is (by definition) the lexicographically earliest permutation of the nonnegative integers with this property.

Examples

			The four integers inside each of the four 2 X 2 squares that contain 0 sum up to a prime: 0+1+2+4=7 / 0+4+3+6=13 / 0+6+5+8=19 / 0+8+10+1=19. This is true for any 2 X 2 square picked up on the (infinite) grid: the upper right corner below sums up to the prime 79 for instance (22+20+30+7).
.
     19--23--25--28--22--20
      |                   |
     24   5---8--10---7  30
      |   |           |   .
     18   6   0---1  11   .
      |   |       |   |   .
     16   3---4---2   9   .
      |               |
     15--13--17--14--12
.
		

Crossrefs

Cf. A214176, A337115 (same idea, with squares instead of primes), A337117 (with palindromes instead of primes), A337368 (with pandigitals).

A337115 Square spiral on a 2D square lattice, one term per cell, starting at the origin with 0; the four integers forming any 2 X 2 square add up to a square.

Original entry on oeis.org

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

Views

Author

Eric Angelini and Jean-Marc Falcoz, Aug 16 2020

Keywords

Comments

This is (by definition) the lexicographically earliest permutation of the nonnegative integers with this property.

Examples

			The four integers inside each of the four 2 X 2 squares that contain the initial 0 add up to a square: 0 + 1 + 2 + 6 = 9, 0 + 6 + 3 + 7 = 16, 0 + 7 + 4 + 5 = 16, 0 + 5 + 10 + 1 = 16. This is true for any 2 X 2 square on the (infinite) grid: the upper right corner below adds up to  81 (= 20 + 18 + 35 + 8), for instance.
.
     15--32--23--26--20--18
      |                   |
     13   4---5--10---8  35
      |   |           |   .
     12   7   0---1  17   .
      |   |       |   |   .
     14   3---6---2  16
      |               |
     11--21--19--22---9
.
		

Crossrefs

Cf. A214176, A337116 (same idea, with primes rather than squares), A337117 (with palindromes), A337368 (with pandigitals).

A337117 Spiral on a 2D square lattice, one term per cell, starting at the origin with 0; the four integers forming any 2 X 2 square add up to a palindrome.

Original entry on oeis.org

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

Views

Author

Eric Angelini and Jean-Marc Falcoz, Aug 16 2020

Keywords

Comments

This is the lexicographically earliest permutation of the nonnegative integers with this property.

Examples

			The four integers inside each of the four 2 X 2 squares that contain 0 sum up to a palindrome: 0+1+2+3=6 / 0+3+4+15=22 / 0+15+5+13=33 / 0+13+8+1=22. This is true for any 2 X 2 square picked up on the (infinite) grid: the upper right corner below sums up to 88 for instance (17+22+43+6).
.
     14--16--32--24--17--22
      |                   |
     20   5--13-- 8---6  43
      |   |           |
     26  15   0---1   7
      |   |       |   |
     21   4---3---2  12
      |               |
     11--19--18--10-- 9
.
		

Crossrefs

Cf. A214176, A337116 (same idea, with primes instead of palindromes), A337115 (squares instead of palindromes).

A214177 Sum of the 4 nearest neighbors of n in a spiral with positive integers.

Original entry on oeis.org

20, 24, 32, 24, 44, 32, 56, 40, 44, 72, 52, 56, 88, 64, 68, 72, 108, 80, 84, 88, 128, 96, 100, 104, 108, 152, 116, 120, 124, 128, 176, 136, 140, 144, 148, 152, 204, 160, 164, 168, 172, 176, 232, 184, 188, 192, 196, 200, 204, 264, 212, 216, 220, 224, 228, 232, 296
Offset: 1

Views

Author

Alex Ratushnyak, Jul 06 2012

Keywords

Comments

Nearby numbers on diagonals are not counted as neighbors for this sequence.

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 four nearest neighbors of 2 are 1, 3, 9, 11. Their sum is a(2) = 24.
		

Crossrefs

Cf. A214176 (sum of the 8 nearest neighbors).

Programs

  • PARI
    See Links section.

Formula

For n >= 3, a(n+1) - a(n) = 4 except if n = k^2/4 + 3*k/2 + (17 - (-1)^k)/8 for some k >= 1 then a(n+1) - a(n) = 4*k + 16 and if n = k^2/4 + 3*k/2 + (25 - (-1)^k)/8 for some k >= 0 then a(n+1) - a(n) = -4*k - 8. - Robert Israel, Dec 14 2023

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=', ')

A365960 Sum of the 6 nearest neighbors of n in a hexagonal spiral with positive integers.

Original entry on oeis.org

27, 38, 40, 48, 56, 64, 54, 78, 86, 72, 100, 84, 114, 96, 128, 108, 142, 120, 126, 162, 138, 176, 150, 156, 196, 168, 174, 216, 186, 192, 236, 204, 210, 256, 222, 228, 234, 282, 246, 252, 302, 264, 270, 276, 328, 288, 294, 300, 354, 312, 318, 324, 380, 336, 342, 348, 406, 360, 366, 372, 378, 438, 390, 396, 402
Offset: 1

Views

Author

Keywords

Examples

			Spiral begins:
                  49--48--47--46--45
                  /                 \
                50  28--27--26--25  44
                /   /             \   \
              51  29  13--12--11  24  43
              /   /   /         \   \   \
            52  30  14   4---3  10  23  42
            /   /   /   /     \   \   \   \
          53  31  15   5   1---2   9  22  41
            \   \   \   \         /   /   /
            54  32  16   6---7---8  21  40
              \   \   \             /   /
               55  33  17--18--19--20  39
                \   \                 /
                56  34--35--36--37--38
                  \
                  57--58--59--60--61
.
The 6 nearest neighbors of 2 are 1,3,7,8,9,10. Their sum is a(2)=38.
		

Crossrefs

Programs

  • Mathematica
    step=9; ta[x_]:=Table[12,x];f=Flatten[Table[Table[{ta[If[m==2,k-1,k]],16+2m+12k},{m,6}],{k,0,step}]][[3;;]];Join[{27,38},f+6Range[3,Length@f+2]]
Showing 1-8 of 8 results.