This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A236345 #24 Jun 07 2025 22:27:16 %S A236345 0,1,3,3,6,10,9,14,9,15,11,18,26,17,26,19,29,40,27,39,24,42,27,39,54, %T A236345 35,51,36,53,71,48,67,42,62,83,56,85,56,79,48,72,97,64,90,55,90,118, %U A236345 81,110,71,101,68,91,123,80,122,77,111,146,99,135,86,123,88,110 %N A236345 a(n) is the Manhattan distance between n and n^2 in a left-aligned triangle with next M natural numbers in row M: 1, 2 3, 4 5 6, 7 8 9 10, etc. %H A236345 Antti Karttunen, <a href="/A236345/b236345.txt">Table of n, a(n) for n = 1..1001</a> %F A236345 a(n) = (A002024(n^2)-A002024(n)) + |A002260(n^2)-A002260(n)|. [Where |x| stands for the absolute value. This formula can be probably reduced further.] - _Antti Karttunen_, Jan 25 2014 %e A236345 The triangle where we measure distances begins as (cf. A000027 drawn as a lower or upper right triangle): %e A236345 1 %e A236345 2 3 %e A236345 4 5 6 %e A236345 7 8 9 10 %e A236345 11 12 13 14 15 %e A236345 16 17 18 19 20 21 %e A236345 22 23 24 25 26 27 28 %e A236345 29 30 31 32 33 34 35 36 %e A236345 37 38 39 40 41 42 43 44 45 %e A236345 Manhattan distance between 5 and 25 in this triangle is 4+2=6, thus a(5)=6. %o A236345 (Python) %o A236345 import math %o A236345 def getXY(n): %o A236345 y = int(math.sqrt(n*2)) %o A236345 if n<=y*(y+1)//2: y-=1 %o A236345 x = n - y*(y+1)//2 %o A236345 return x, y %o A236345 for n in range(1,77): %o A236345 ox, oy = getXY(n) %o A236345 nx, ny = getXY(n*n) %o A236345 print(str(abs(nx-ox)+abs(ny-oy)), end=',') %o A236345 (Python) %o A236345 from math import isqrt, comb %o A236345 def A236345(n): return (isqrt(n**2<<3)+1>>1)-(isqrt(n<<3)+1>>1)+abs(n*(n-1)-comb((m2:=isqrt(k2:=n**2<<1))+(k2>m2*(m2+1)),2)+comb((m:=isqrt(k:=n<<1))+(k>m*(m+1)),2)) # _Chai Wah Wu_, Jun 07 2025 %o A236345 (Scheme) (define (A236345 n) (+ (- (A002024 (A000290 n)) (A002024 n)) (abs (- (A002260 (A000290 n)) (A002260 n))))) ;; _Antti Karttunen_, Jan 25 2014 %Y A236345 Cf. A232114, A236346, A236347. %Y A236345 Cf. also A000027, A002024, A002260. %K A236345 nonn,easy %O A236345 1,3 %A A236345 _Alex Ratushnyak_, Jan 23 2014