What is an algorithm to get the nth element of a rectangular tiled spiral?
Here is n
:
[ 20 ][ 21 ][ 22 ][ 23 ][ 24 ]
[ 19 ][ 6 ][ 7 ][ 8 ][ 9 ]
[ 18 ][ 5 ][ 0 ][ 1 ][ 10 ]
[ 17 ][ 4 ][ 3 ][ 2 ][ 11 ]
[ 16 ][ 15 ][ 14 ][ 13 ][ 12 ]
and here are the corresponding coordinates for n
:
[-2,2 ][-1,2 ][ 0,2 ][ 1,2 ][ 2,2 ]
[-2,1 ][-1,1 ][ 0,1 ][ 1,1 ][ 2,1 ]
[-2,0 ][-1,0 ][ 0,0 ][ 1,0 ][ 2,0 ]
[-2,-1][-1,-1][ 0,-1][ 1,-1][ 2,-1]
[-2,-2][-1,-2][ 0,-2][ 1,-2][ 2,-2]
If given n
, how to calculate the coordinates?