|
|
A214250
|
|
Sum of the eight nearest neighbors of n in a triangular "horizontal-first" spiral with positive integers.
|
|
4
|
|
|
56, 80, 108, 84, 132, 92, 84, 96, 128, 200, 152, 144, 236, 160, 172, 204, 284, 212, 188, 184, 192, 200, 208, 232, 280, 384, 304, 280, 280, 288, 428, 304, 312, 320, 340, 388, 500, 396, 356, 344, 352, 360, 368, 376, 384, 392, 400, 432, 496, 632, 520, 480, 472, 480
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,1
|
|
LINKS
|
|
|
EXAMPLE
|
Spiral begins:
__ __ __ __ __ __ __ 57
__ __ __ __ __ __ 56 31 58
__ __ __ __ __ 55 30 13 32 59
__ __ __ __ 54 29 12 3 14 33 60
__ __ __ 53 28 11 2 1 4 15 34 61
__ __ 52 27 10 9 8 7 6 5 16 35 62
__ 51 26 25 24 23 22 21 20 19 18 17 36 63
50 49 48 47 46 45 44 43 42 41 40 39 38 37 64
The eight nearest neighbors of 4 are: 1, 3, 14, 33, 15, 5, 6, 7. Their sum is a(4)=84.
|
|
PROG
|
(Python)
SIZE=29 # must be odd
grid = [0] * (SIZE*SIZE)
saveX = [0]* (SIZE*SIZE)
saveY = [0]* (SIZE*SIZE)
saveX[1] = saveY[1] = posX = posY = SIZE//2
grid[posY*SIZE+posX]=1
n = 2
def walk(stepX, stepY, chkX, chkY, chkX2, chkY2):
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==0 or grid[(posY+chkY)*SIZE+posX+chkX]+grid[(posY+chkY2)*SIZE+posX+chkX2]==0:
return
while 1:
walk(-1, 0, 1, -1, 0, -1) # left
if posX==0:
break
walk( 1, -1, 1, 1, 1, 1) # right+up
walk( 1, 1, -1, 0, -1, 0) # right+down
for n in range(1, 122):
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]
k+= grid[posY*SIZE+posX-1] + grid[posY*SIZE+posX+1]
print k,
|
|
CROSSREFS
|
Cf. A214226 - same sum in a triangular "horizontal-last" spiral.
|
|
KEYWORD
|
nonn,easy
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|