%I #4 Sep 24 2012 13:35:24
%S 1,3,14,4,6,7,8,2,12,30,13,32,59,33,15,5,19,20,21,22,23,9,11,29,55,89,
%T 56,31,58,93,136,94,60,34,16,18,40,41,42,43,44,45,46,24,10,28,54,88,
%U 130,180,131,90,57,92,135,186,245,187,137,95,61,35,17,39,69
%N Permutation of natural numbers arising from applying the walk of a square spiral (e.g. A214526) to the data of triangular horizontal-first spiral (defined in A214250).
%o (Python)
%o SIZE = 33 # 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<SIZE-2:
%o walk(-1, 0, 1, -1) # left
%o walk(1, -1, 1, 1) # up-right
%o walk(1, 1, -1, 0) # down-right
%o walk(-1, 0, 1, -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 1:
%o walk2(0, -1, 1, 0) # up
%o walk2(1, 0, 0, 1) # right
%o walk2(0, 1, -1, 0) # down
%o walk2(-1, 0, 0, -1) # left
%Y Cf. A090861, A214526, A214250, A217010.
%K nonn,easy
%O 1,2
%A _Alex Ratushnyak_, Sep 23 2012
|