OFFSET
1,3
LINKS
Antti Karttunen, Table of n, a(n) for n = 1..1001
FORMULA
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
EXAMPLE
The triangle where we measure distances begins as (cf. A000027 drawn as a lower or upper right triangle):
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
Manhattan distance between 5 and 25 in this triangle is 4+2=6, thus a(5)=6.
PROG
(Python)
import math
def getXY(n):
y = int(math.sqrt(n*2))
if n<=y*(y+1)//2: y-=1
x = n - y*(y+1)//2
return x, y
for n in range(1, 77):
ox, oy = getXY(n)
nx, ny = getXY(n*n)
print(str(abs(nx-ox)+abs(ny-oy)), end=', ')
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Alex Ratushnyak, Jan 23 2014
STATUS
approved