Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,21 @@
function a = spiral(n)
a = ones(n*n, 1);
u = -(i = n) * (v = ones(n, 1));
for k = n-1:-1:1
j = 1:k;
a(j+i) = u(j) = -u(j);
a(j+(i+k)) = v(j) = -v(j);
i += 2*k;
endfor
a(cumsum(a)) = 1:n*n;
a = reshape(a, n, n)'-1;
endfunction
>> spiral(5)
ans =
0 1 2 3 4
15 16 17 18 5
14 23 24 19 6
13 22 21 20 7
12 11 10 9 8