login
A214251
Sum of the eight nearest neighbors of n in a right triangular type-2 spiral with positive integers.
5
62, 64, 69, 125, 94, 111, 170, 118, 105, 116, 169, 132, 131, 151, 192, 284, 217, 201, 206, 220, 258, 353, 265, 234, 227, 235, 243, 269, 349, 285, 275, 283, 291, 299, 328, 387, 515, 412, 378, 374, 382, 390, 398, 421, 477, 608, 484, 435, 419, 427, 435
OFFSET
1,1
COMMENTS
Right triangular type-1 spiral (A214230): implements the sequence Up, Right-down, Left.
Right triangular type-2 spiral: Left, Up, Right-down.
Right triangular type-3 spiral (A214252): Right-down, Left, Up.
EXAMPLE
Right triangular type-2 spiral begins:
67
66 68
65 37 69
64 36 38 70
63 35 16 39 71
62 34 15 17 40 72
61 33 14 4 18 41 73
60 32 13 3 5 19 42 74
59 31 12 2 1 6 20 43 75
58 30 11 10 9 8 7 21 44 76
57 29 28 27 26 25 24 23 22 45 77
56 55 54 53 52 51 50 49 48 47 46 78
The eight nearest neighbors of 5 are 1, 2, 3, 4, 18, 41, 19, 6. Their sum is a(5)=94.
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):
global posX, posY, n
while 1:
posX+=stepX
posY+=stepY
grid[posY*SIZE+posX]=n
saveX[n]=posX
saveY[n]=posY
n+=1
if posY==0 or grid[(posY+chkY)*SIZE+posX+chkX]==0:
return
while 1:
walk(-1, 0, 0, -1) # left
walk(0, -1, 1, 1) # up
if posY==0:
break
walk( 1, 1, -1, 0) # right-down
for n in range(1, 92):
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. A214230.
Cf. A214252.
Sequence in context: A076764 A367090 A345496 * A031058 A084801 A095577
KEYWORD
nonn,easy
AUTHOR
Alex Ratushnyak, Jul 08 2012
STATUS
approved