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

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

A137931 Sum of the principal diagonals of a 2n X 2n square spiral.

Original entry on oeis.org

0, 10, 56, 170, 384, 730, 1240, 1946, 2880, 4074, 5560, 7370, 9536, 12090, 15064, 18490, 22400, 26826, 31800, 37354, 43520, 50330, 57816, 66010, 74944, 84650, 95160, 106506, 118720, 131834, 145880, 160890, 176896, 193930, 212024, 231210, 251520, 272986, 295640
Offset: 0

Views

Author

William A. Tedeschi, Feb 29 2008

Keywords

Comments

This is concerned with 2n X 2n square spirals of the form illustrated in the Example section.

Examples

			Example with n = 2:
.
   7---8---9--10
   |           |
   6   1---2  11
   |       |   |
   5---4---3  12
               |
  16--15--14--13
.
a(0) = 2(0)^2 + 2(0) + (16(0)^3 + 2(0))/3 =  0;
a(2) = 2(2)^2 + 2(2) + (16(2)^3 + 2(2))/3 = 56.
		

Crossrefs

Cf. A137928, A002061. A bisection of A137930.

Programs

  • Python
    f = lambda n: -1 + n + sum(2*k**2 - k + 1 for k in range(0,2*n+1))
    
  • Python
    a = lambda n: 2*n**2 + 2*n + (16*n**3 + 2*n)/3

Formula

a(n) = -1 + n + Sum_{k=0..2n} (2k^2 - k + 1) = n -1 +(2*n+1)*(8*n^2-n+3)/3.
a(n) = 2*n^2 + 2*n + (16*n^3 + 2*n)/3 = 2*n*(8*n^2+3*n+4)/3.
G.f.: 2*x*(3*x+5)*(x+1)/(x-1)^4. - Maksym Voznyy (voznyy(AT)mail.ru), Jul 27 2009

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=', ')
Showing 1-5 of 5 results.