login
Permutation of natural numbers arising from applying the walk of square spiral (e.g. A214526) to the data of double square spiral (defined in A220098).
0

%I #8 Dec 05 2012 12:20:34

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

%T 28,30,32,34,36,38,40,42,44,46,48,27,29,31,33,35,37,39,41,43,45,47,49,

%U 51,53,55,57,59,61,63,65,67,69,71,73,75,77,79,81,50,52,54,56

%N Permutation of natural numbers arising from applying the walk of square spiral (e.g. A214526) to the data of double square spiral (defined in A220098).

%o (C)

%o #include <stdio.h>

%o #define SIZE 20

%o int grid[SIZE][SIZE];

%o int direction[] = {0, -1, 1, 0, 0, 1, -1, 0};

%o main() {

%o int i, j, x1, y1, x2, y2, stepSize;

%o int direction1pos=0, direction2pos=4, val;

%o x1 = y1 = x2 = y2 = SIZE/2;

%o for (val=grid[y1][x1]=1, stepSize=0; ; ++stepSize) {

%o if (x1<1 || x1>=SIZE-1 || x2<1 || x2>=SIZE-1) break;

%o if (y1<1 || y1>=SIZE-1 || y2<1 || y2>=SIZE-1) break;

%o for (i=stepSize|1; i; ++val,--i) {

%o x1 += direction[direction1pos ];

%o y1 += direction[direction1pos+1];

%o x2 += direction[direction2pos ];

%o y2 += direction[direction2pos+1];

%o grid[y1][x1] = val*2;

%o grid[y2][x2] = val*2+1;

%o }

%o direction1pos = (direction1pos+2) & 7;

%o direction2pos = (direction2pos+2) & 7;

%o }

%o direction1pos=0;

%o x1 = y1 = SIZE/2;

%o for (stepSize=2; ; ++stepSize) {

%o for (i=stepSize/2; i; --i) {

%o if (grid[y1][x1]==0) return;

%o printf("%d, ",grid[y1][x1]);

%o x1 += direction[direction1pos ];

%o y1 += direction[direction1pos+1];

%o }

%o direction1pos = (direction1pos+2) & 7;

%o }

%o }

%Y Cf. A214526, A220098, A217010, A217011, A217012, A217013, A217014, A217015.

%K nonn

%O 1,2

%A _Alex Ratushnyak_, Dec 04 2012