%I #36 Oct 25 2019 11:16:43
%S 0,1,2,1,2,1,2,1,2,3,2,3,4,3,2,3,4,3,2,3,4,3,2,3,4,5,4,3,4,5,6,5,4,3,
%T 4,5,6,5,4,3,4,5,6,5,4,3,4,5,6,7,6,5,4,5,6,7,8,7,6,5,4,5,6,7,8,7,6,5,
%U 4,5,6,7,8,7,6,5,4,5,6,7,8,9,8,7,6,5,6,7,8,9,10,9,8,7,6,5,6,7,8,9,10,9,8,7,6,5,6,7,8,9,10,9,8,7,6,5,6,7,8,9,10
%N Manhattan distances between n and 1 in a square spiral with positive integers and 1 at the center.
%C Spiral begins:
%C 49 26--27--28--29--30--31
%C | | |
%C 48 25 10--11--12--13 32
%C | | | | |
%C 47 24 9 2---3 14 33
%C | | | | | | |
%C 46 23 8 1 4 15 34
%C | | | | | |
%C 45 22 7---6---5 16 35
%C | | | |
%C 44 21--20--19--18--17 36
%C | |
%C 43--42--41--40--39--38--37
%H Michael De Vlieger, <a href="/A214526/b214526.txt">Table of n, a(n) for n = 1..10201</a>
%F abs( a(n) - a(n-1) ) = 1.
%F For n > 1, a(n) = layer(n) + abs(((n-1) mod (2*layer(n)) - layer(n))) (conjectured) where layer(n) = ceiling(0.5*sqrt(n) - 0.5). - _Karl R. Stephan_, Jan 26 2018
%F a(n) = abs(A174344(n)) + abs(A274923(n)). - _Kevin Ryde_, Oct 25 2019
%t f[n_] := Block[{o = 2 n - 1, t, w}, t = Table[0, {o}, {o}]; t = ReplacePart[t, {n, n} -> 1]; Do[w = Partition[Range[(2 (# - 1) - 1)^2 + 1, (2 # - 1)^2], 2 (# - 1)] &@ k; Do[t = ReplacePart[t, {(n + k) - (j + 1), n + (k - 1)} -> #[[1, j]]]; t = ReplacePart[t, {n - (k - 1), (n + k) - (j + 1)} -> #[[2, j]]]; t = ReplacePart[t, {(n - k) + (j + 1), n - (k - 1)} -> #[[3, j]]]; t = ReplacePart[t, {n + (k - 1), (n - k) + (j + 1)} -> #[[4, j]]], {j, 2 (k - 1)}] &@ w, {k, 2, n}]; t]; With[{x = Position[#, 1][[1]]}, Table[Total@ Abs[Position[#, n][[1]] - x], {n, Max@ #}]] &@ f@ 6 (* _Michael De Vlieger_, Feb 16 2018 *)
%o (PARI) a(n) = n--; my(m=sqrtint(n),k=ceil(m/2)); n=abs(n-4*k^2); k+abs(n-if(n>m,3,1)*k); \\ _Kevin Ryde_, Oct 25 2019
%Y Cf. A137928, A137930, A137931, A002061, A114254, A214176, A214177.
%K nonn,easy
%O 1,3
%A _Alex Ratushnyak_, Aug 08 2012
|