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.

A214226 Sum of the eight nearest neighbors of n in a triangular horizontal-last spiral with positive integers.

This page as a plain text file.
%I A214226 #20 Nov 11 2024 20:30:28
%S A214226 72,80,60,76,132,100,164,112,136,200,144,128,128,136,156,196,284,220,
%T A214226 204,208,324,224,232,248,288,384,296,264,256,264,272,280,288,296,324,
%U A214226 380,500,404,372,368,376,384,548,400,408,416,424,448,504,632,512,464,448
%N A214226 Sum of the eight nearest neighbors of n in a triangular horizontal-last spiral with positive integers.
%e A214226 Triangular spiral begins:
%e A214226 __ __ __ __ __ __ __ 43
%e A214226 __ __ __ __ __ __ 42 21 44
%e A214226 __ __ __ __ __ 41 20  7 22 45
%e A214226 __ __ __ __ 40 19  6  1  8 23 46
%e A214226 __ __ __ 39 18  5  4  3  2  9 24 47
%e A214226 __ __ 38 17 16 15 14 13 12 11 10 25 48
%e A214226 __ 37 36 35 34 33 32 31 30 29 28 27 26 49
%e A214226 64 63 62 61 60 69 58 57 56 55 54 53 52 51 50
%e A214226 The eight nearest neighbors of 3 are 6, 1, 8, 4, 2, 14, 13, 12; their sum is a(3)=60.
%o A214226 (Python)
%o A214226 SIZE=27 # must be odd
%o A214226 grid = [0] * (SIZE*SIZE)
%o A214226 saveX = [0]* (SIZE*SIZE)
%o A214226 saveY = [0]* (SIZE*SIZE)
%o A214226 saveX[1] = saveY[1] = posX = posY = SIZE//2
%o A214226 grid[posY*SIZE+posX]=1
%o A214226 n = 2
%o A214226 def walk(stepX,stepY,chkX,chkY,chkX2,chkY2):
%o A214226   global posX, posY, n
%o A214226   while 1:
%o A214226     posX+=stepX
%o A214226     posY+=stepY
%o A214226     grid[posY*SIZE+posX]=n
%o A214226     saveX[n]=posX
%o A214226     saveY[n]=posY
%o A214226     n+=1
%o A214226     if posX==0 or grid[(posY+chkY)*SIZE+posX+chkX]+grid[(posY+chkY2)*SIZE+posX+chkX2]==0:
%o A214226         return
%o A214226 while 1:
%o A214226     walk( 1, 1, -1,  0, -1, 0)    # right+down
%o A214226     walk(-1, 0,  1, -1, 0, -1)    # left
%o A214226     if posX==0:
%o A214226         break
%o A214226     walk( 1,-1,  1, 1, 1, 1)    # right+up
%o A214226 for n in range(1,101):
%o A214226     posX = saveX[n]
%o A214226     posY = saveY[n]
%o A214226     k = grid[(posY-1)*SIZE+posX] + grid[(posY+1)*SIZE+posX]
%o A214226     k+= grid[(posY-1)*SIZE+posX-1] + grid[(posY-1)*SIZE+posX+1]
%o A214226     k+= grid[(posY+1)*SIZE+posX-1] + grid[(posY+1)*SIZE+posX+1]
%o A214226     k+= grid[posY*SIZE+posX-1] + grid[posY*SIZE+posX+1]
%o A214226     print(k, end=', ')
%Y A214226 Cf. A002061 - numbers on the central vertical axis.
%Y A214226 Cf. A054552 - numbers on the axis starting with 1 and 2.
%Y A214226 Cf. A214227 - sum of the four nearest neighbors.
%Y A214226 Cf. A214250 - same sum in a triangular "horizontal-first" spiral.
%K A214226 nonn,easy
%O A214226 1,1
%A A214226 _Alex Ratushnyak_, Jul 07 2012