login
A214176
Sum of the 8 nearest neighbors of n in a spiral with positive integers.
9
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,1
LINKS
EXAMPLE
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.
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 *)
PROG
(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],
(PARI) See Links section.
CROSSREFS
Cf. A214177 (sum of the 4 nearest neighbors).
Sequence in context: A270298 A231402 A116227 * A306116 A185590 A029690
KEYWORD
nonn,easy
AUTHOR
Alex Ratushnyak, Jul 06 2012
STATUS
approved