OFFSET
1,2
LINKS
PROG
(Python)
SIZE = 29 # 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 posX:
walk(0, -1, 1, 0) # up
walk(1, 0, 0, 1) # right
walk(0, 1, -1, 0) # down
walk(-1, 0, 0, -1) # left
grid2 = [0] * (SIZE*SIZE)
posY = SIZE//2
posX = posY+1
grid2[posY*SIZE+posX-1] = grid2[posY*SIZE+posX] = 1
print(1, end=', ')
def walk2(stepX, stepY, chkX, chkY):
global posX, posY
while 1:
a = grid[posY*SIZE+posX]
if a==0:
raise ValueError
print(a, end=', ')
posX+=stepX
posY+=stepY
grid2[posY*SIZE+posX]=1
if grid2[(posY+chkY)*SIZE+posX+chkX]==0:
return
while posX!=SIZE-1:
walk2(-1, 1, -1, -1) # down-left
walk2(-1, -1, 1, -1) # up-left
walk2( 1, -1, 1, 0) # up-right
walk2( 1, 0, 1, 1) # right
walk2( 1, 1, -1, 1) # down-right
CROSSREFS
KEYWORD
nonn
AUTHOR
Alex Ratushnyak, Sep 30 2012
STATUS
approved