login
Permutation of natural numbers arising from applying the walk of right triangular type-3 spiral (defined in A214252) to the data of square spiral (e.g. A214526).
0

%I #5 Oct 01 2012 01:49:44

%S 1,5,6,7,8,9,10,2,4,16,36,17,18,19,20,21,22,23,24,25,26,51,27,11,3,15,

%T 35,63,99,64,37,38,39,40,41,42,43,44,45,46,47,48,49,50,83,124,84,52,

%U 28,12,14,34,62,98,142,194,143,100,65,66,67,68,69,70,71,72

%N Permutation of natural numbers arising from applying the walk of right triangular type-3 spiral (defined in A214252) to the data of square spiral (e.g. A214526).

%o (Python)

%o SIZE = 29 # must be 4k+1

%o grid = [0] * (SIZE*SIZE)

%o posX = posY = SIZE//2

%o grid[posY*SIZE+posX]=1

%o n = 2

%o def walk(stepX, stepY, chkX, chkY):

%o global posX, posY, n

%o while 1:

%o posX+=stepX

%o posY+=stepY

%o grid[posY*SIZE+posX]=n

%o n+=1

%o if grid[(posY+chkY)*SIZE+posX+chkX]==0:

%o return

%o while posX:

%o walk(0, -1, 1, 0) # up

%o walk(1, 0, 0, 1) # right

%o walk(0, 1, -1, 0) # down

%o walk(-1, 0, 0, -1) # left

%o import sys

%o grid2 = [0] * (SIZE*SIZE)

%o posX = posY = SIZE//2

%o grid2[posY*SIZE+posX]=1

%o def walk2(stepX, stepY, chkX, chkY):

%o global posX, posY

%o while 1:

%o a = grid[posY*SIZE+posX]

%o if a==0:

%o sys.exit(1)

%o print a,

%o posX+=stepX

%o posY+=stepY

%o grid2[posY*SIZE+posX]=1

%o if grid2[(posY+chkY)*SIZE+posX+chkX]==0:

%o return

%o while posY!=0:

%o walk2( 1, 1, -1, 0) # right-down

%o walk2(-1, 0, 0, -1) # left

%o walk2(0, -1, 1, 1) # up

%Y Cf. A214252, A214526, A217012.

%K nonn

%O 1,2

%A _Alex Ratushnyak_, Sep 30 2012