%I #12 May 09 2021 09:51:50
%S 1,4,6,8,2,3,15,5,19,7,23,9,11,12,14,34,16,18,40,20,22,46,24,10,28,29,
%T 13,33,61,35,17,39,69,41,21,45,77,47,25,27,53,54,30,32,60,96,62,36,38,
%U 68,106,70,42,44,76,116,78,48,26,52,86,87,55,31,59,95,139
%N Permutation of natural numbers arising from applying the walk of rotated-square spiral (defined in A215468) to the data of square spiral (e.g. A214526).
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%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 grid2 = [0] * (SIZE*SIZE)
%o posY = SIZE//2
%o posX = posY+1
%o grid2[posY*SIZE+posX-1] = grid2[posY*SIZE+posX] = 1
%o print(1, end=',')
%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 raise ValueError
%o print(a, end=',')
%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 posX!=SIZE-1:
%o walk2(-1, 1, -1, -1) # down-left
%o walk2(-1, -1, 1, -1) # up-left
%o walk2( 1, -1, 1, 0) # up-right
%o walk2( 1, 0, 1, 1) # right
%o walk2( 1, 1, -1, 1) # down-right
%Y Cf. A215468, A214526, A217015.
%K nonn
%O 1,2
%A _Alex Ratushnyak_, Sep 30 2012