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.

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

This page as a plain text file.
%I A214176 #25 Jan 31 2025 17:36:52
%S A214176 44,58,72,62,96,82,120,94,104,152,120,130,184,146,144,164,224,180,176,
%T A214176 198,264,214,208,216,240,312,256,248,256,282,360,298,288,296,304,332,
%U A214176 416,348,336,344,352,382,472,398,384,392,400,408,440,536,456,440
%N A214176 Sum of the 8 nearest neighbors of n in a spiral with positive integers.
%H A214176 Rémy Sigrist, <a href="/A214176/b214176.txt">Table of n, a(n) for n = 1..5202</a>
%H A214176 Rémy Sigrist, <a href="/A214176/a214176.gp.txt">PARI program for A214176</a>
%e A214176 Spiral begins:
%e A214176 .
%e A214176   49  26--27--28--29--30--31
%e A214176    |   |                   |
%e A214176   48  25  10--11--12--13  32
%e A214176    |   |   |           |   |
%e A214176   47  24   9   2---3  14  33
%e A214176    |   |   |   |   |   |   |
%e A214176   46  23   8   1   4  15  34
%e A214176    |   |   |       |   |   |
%e A214176   45  22   7---6---5  16  35
%e A214176    |   |               |   |
%e A214176   44  21--20--19--18--17  36
%e A214176    |                       |
%e A214176   43--42--41--40--39--38--37
%e A214176 .
%e A214176 The 8 nearest neighbors of 2 are 1,3,4,8,9,10,11,12. Their sum is a(2)=58.
%t A214176 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 *)
%o A214176 (Python)
%o A214176 SIZE=11  # must be odd
%o A214176 grid = [0] * (SIZE*SIZE)
%o A214176 posX = posY = SIZE//2
%o A214176 grid[posY*SIZE+posX]=1
%o A214176 n = 2
%o A214176 saveX = [0]* (SIZE*SIZE+1)
%o A214176 saveY = [0]* (SIZE*SIZE+1)
%o A214176 saveX[1]=posX
%o A214176 saveY[1]=posY
%o A214176 def walk(stepX,stepY,chkX,chkY):
%o A214176   global posX, posY, n
%o A214176   while 1:
%o A214176     posX+=stepX
%o A214176     posY+=stepY
%o A214176     grid[posY*SIZE+posX]=n
%o A214176     saveX[n]=posX
%o A214176     saveY[n]=posY
%o A214176     n+=1
%o A214176     if posX+posY==0 or grid[(posY+chkY)*SIZE+posX+chkX]==0:
%o A214176         return
%o A214176 while 1:
%o A214176     walk(0,-1, 1, 0)    # up
%o A214176     if posX+posY==0:
%o A214176         break
%o A214176     walk(1, 0, 0, 1)    # right
%o A214176     walk(0, 1,-1, 0)    # down
%o A214176     walk(-1,0, 0,-1)    # left
%o A214176 for n in range(1,(SIZE-2)*(SIZE-2)+1):
%o A214176     posX = saveX[n]
%o A214176     posY = saveY[n]
%o A214176     k = grid[(posY-1)*SIZE+posX] + grid[(posY+1)*SIZE+posX]
%o A214176     k+= grid[(posY-1)*SIZE+posX-1] + grid[(posY-1)*SIZE+posX+1]
%o A214176     k+= grid[(posY+1)*SIZE+posX-1] + grid[(posY+1)*SIZE+posX+1]
%o A214176     print(k+grid[posY*SIZE+posX-1] + grid[posY*SIZE+posX+1], end=', ')
%o A214176 (PARI) \\ See Links section.
%Y A214176 Cf. A002061, A114254, A137928, A137930, A137931.
%Y A214176 Cf. A214177 (sum of the 4 nearest neighbors).
%K A214176 nonn,easy
%O A214176 1,1
%A A214176 _Alex Ratushnyak_, Jul 06 2012