Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #19 May 13 2021 01:18:49
%S 50,62,72,86,76,84,122,88,144,104,166,120,152,160,144,218,160,168,248,
%T 184,192,278,208,216,260,268,240,248,346,264,272,280,384,296,304,312,
%U 422,328,336,344,400,408,368,376,384,506,400,408,416,424,552,440,448,456,464,598
%N Sum of the 8 nearest neighbors of n in a rotated-square spiral with positive integers.
%e Spiral begins:
%e 85
%e /
%e /
%e 84 61-62
%e / / \
%e / / \
%e 83 60 41-42 63
%e / / / \ \
%e / / / \ \
%e 82 59 40 25-26 43 64
%e / / / / \ \ \
%e / / / / \ \ \
%e 81 58 39 24 13-14 27 44 65
%e / / / / / \ \ \ \
%e / / / / / \ \ \ \
%e 80 57 38 23 12 5--6 15 28 45 66
%e / / / / / / \ \ \ \ \
%e / / / / / / \ \ \ \ \
%e 79 56 37 22 11 4 1--2 7 16 29 46 67
%e \ \ \ \ \ \ / / / / / /
%e \ \ \ \ \ \ / / / / / /
%e 78 55 36 21 10 3 8 17 30 47 68
%e \ \ \ \ \ / / / / /
%e \ \ \ \ \ / / / / /
%e 77 54 35 20 9 18 31 48 69
%e \ \ \ \ / / / /
%e \ \ \ \ / / / /
%e 76 53 34 19 32 49 70
%e \ \ \ / / /
%e \ \ \ / / /
%e 75 52 33 50 71
%e \ \ / /
%e \ \ / /
%e 74 51 72
%e \ /
%e \ /
%e 73
%e .
%e The 8 nearest neighbors of 4 are 1,3,5,10,11,12,21,23, their sum is 86, so a(4)=86.
%o (Python)
%o SIZE=17 # must be odd
%o grid = [0] * (SIZE*SIZE)
%o posX = posY = SIZE//2
%o saveX = [0]* (SIZE*SIZE+1)
%o saveY = [0]* (SIZE*SIZE+1)
%o grid[posY*SIZE+posX]=1
%o saveX[1]=posX
%o saveY[1]=posY
%o posX += 1
%o grid[posY*SIZE+posX]=2
%o saveX[2]=posX
%o saveY[2]=posY
%o n = 3
%o def walk(stepX, stepY, chkX, chkY):
%o global posX, posY, n
%o while 1:
%o posX+=stepX
%o posY+=stepY
%o grid[posY*SIZE+posX]=n
%o saveX[n]=posX
%o saveY[n]=posY
%o n+=1
%o if grid[(posY+chkY)*SIZE+posX+chkX]==0:
%o return
%o while posX!=SIZE-1:
%o walk(-1, 1, -1, -1) # down-left
%o walk(-1, -1, 1, -1) # up-left
%o walk( 1, -1, 1, 0) # up-right
%o walk( 1, 0, 1, 1) # right
%o walk( 1, 1, -1, 1) # down-right
%o for s in range(1, n):
%o posX = saveX[s]
%o posY = saveY[s]
%o i,j = grid[(posY-1)*SIZE+posX-1], grid[(posY-1)*SIZE+posX+1]
%o u,v = grid[(posY+1)*SIZE+posX-1], grid[(posY+1)*SIZE+posX+1]
%o if i==0 or j==0 or u==0 or v==0:
%o break
%o k = grid[(posY-1)*SIZE+posX ] + grid[(posY+1)*SIZE+posX ]
%o k+= grid[ posY *SIZE+posX-1] + grid[ posY *SIZE+posX+1]
%o print i+j+u+v+k,
%o print
%o for y in range(SIZE):
%o for x in range(SIZE):
%o print '%3d' % grid[y*SIZE+x],
%o print
%Y Coordinates (but 0-based): A010751, A305258.
%Y Other spiral sums: A214176, A214177, A214226, A214227, A214230, A214231, A214250, A214251, A214252.
%K nonn,easy
%O 1,1
%A _Alex Ratushnyak_, Aug 11 2012