login
A217012
Permutation of natural numbers arising from applying the walk of a square spiral (e.g. A214526) to the data of right triangular type-3 spiral (defined in A214252).
2
1, 8, 25, 9, 2, 3, 4, 5, 6, 7, 24, 50, 85, 51, 26, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 49, 84, 128, 181, 129, 86, 52, 27, 11, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 22, 48, 83, 127, 180, 242
OFFSET
1,2
PROG
(Python)
SIZE = 33 # must be 4k+1
grid = [0] * (SIZE*SIZE)
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
n+=1
if grid[(posY+chkY)*SIZE+posX+chkX]==0:
return
while posY!=0:
walk( 1, 1, -1, 0) # right-down
walk(-1, 0, 0, -1) # left
walk(0, -1, 1, 1) # up
import sys
grid2 = [0] * (SIZE*SIZE)
posX = posY = SIZE//2
grid2[posY*SIZE+posX]=1
def walk2(stepX, stepY, chkX, chkY):
global posX, posY
while 1:
a = grid[posY*SIZE+posX]
if a==0:
sys.exit(1)
print a,
posX+=stepX
posY+=stepY
grid2[posY*SIZE+posX]=1
if grid2[(posY+chkY)*SIZE+posX+chkX]==0:
return
while 1:
walk2(0, -1, 1, 0) # up
walk2(1, 0, 0, 1) # right
walk2(0, 1, -1, 0) # down
walk2(-1, 0, 0, -1) # left
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Alex Ratushnyak, Sep 23 2012
STATUS
approved