login
A217294
Permutation of natural numbers arising from applying the walk of triangular horizontal-first spiral (defined in A214250) to the data of square spiral (e.g. A214526).
0
1, 8, 2, 4, 16, 5, 6, 7, 22, 45, 23, 9, 11, 3, 15, 35, 63, 36, 17, 18, 19, 20, 21, 44, 75, 114, 76, 46, 24, 10, 28, 12, 14, 34, 62, 98, 142, 99, 64, 37, 38, 39, 40, 41, 42, 43, 74, 113, 160, 215, 161, 115, 77, 47, 25, 27, 53, 29, 13, 33, 61, 97, 141, 193, 253
OFFSET
1,2
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
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, end=', ')
posX+=stepX
posY+=stepY
grid2[posY*SIZE+posX]=1
if grid2[(posY+chkY)*SIZE+posX+chkX]==0:
return
while posX<SIZE-2:
walk2(-1, 0, 1, -1) # left
walk2(1, -1, 1, 1) # up-right
walk2(1, 1, -1, 0) # down-right
walk2(-1, 0, 1, -1) # left
CROSSREFS
KEYWORD
nonn,changed
AUTHOR
Alex Ratushnyak, Sep 30 2012
STATUS
approved