OFFSET
1,1
COMMENTS
Right triangular type-1 spiral implements the sequence Up, Right-down, Left.
Right triangular type-2 spiral (A214251): Left, Up, Right-down.
Right triangular type-3 spiral (A214252): Right-down, Left, Up.
A140064 -- rightwards from 1: 3,14,34...
A064225 -- leftwards from 1: 8,24,49...
A117625 -- upwards from 1: 2,12,31...
A006137 -- downwards from 1: 6,20,43...
A038764 -- left-down from 1: 7,22,46...
A081267 -- left-up from 1: 9,26,52...
A081589 -- right-up from 1: 13, 61, 145...
9*x^2/2 - 19*x/2 + 6 -- right-down from 1: 5,18,40...
EXAMPLE
Right triangular spiral begins:
56
55 57
54 29 58
53 28 30 59
52 27 11 31 60
51 26 10 12 32 61
50 25 9 2 13 33 62
49 24 8 1 3 14 34 63
48 23 7 6 5 4 15 35 64
47 22 21 20 19 18 17 16 36 65
46 45 44 43 42 41 40 39 38 37 66
78 77 76 75 74 73 72 71 70 69 68 67
The eight nearest neighbors of 3 are 1, 2, 13, 33, 14, 4, 5, 6. Their sum is a(3)=78.
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(0, -1, 1, 1) # up
if posY==0:
break
walk( 1, 1, -1, 0) # right-down
walk(-1, 0, 0, -1) # left
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
KEYWORD
nonn,easy
AUTHOR
Alex Ratushnyak, Jul 08 2012
STATUS
approved