A214526 Manhattan distances between n and 1 in a square spiral with positive integers and 1 at the center.
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, 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, 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
Offset: 1
Links
- Michael De Vlieger, Table of n, a(n) for n = 1..10201
Programs
-
Mathematica
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 *)
-
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
Formula
abs( a(n) - a(n-1) ) = 1.
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
Comments