%I #13 May 09 2021 09:52:02
%S 0,1,2,1,2,3,4,3,2,3,4,5,6,5,4,3,4,5,6,7,8,7,6,5,4,5,6,7,8,9,10,9,8,7,
%T 6,5,6,7,8,9,10,11,12,11,10,9,8,7,6,7,8,9,10,11,12,13,14,13,12,11,10,
%U 9,8,7,8,9,10,11,12,13,14,15,16,15,14,13,12,11
%N The Manhattan distance to the origin while traversing the first quadrant in a taxicab geometry.
%o (Python)
%o def f(x, y):
%o if not x and y % 2:
%o y = y + 1
%o elif not y and not x % 2:
%o x = x + 1
%o elif x == y:
%o if x % 2:
%o x = x - 1
%o else:
%o y = y - 1
%o elif y < x:
%o if x % 2:
%o y = y + 1
%o else:
%o y = y - 1
%o else:
%o if y % 2:
%o x = x - 1
%o else:
%o x = x + 1
%o return x, y
%o res = []
%o x = y = 0
%o for i in range(100):
%o res.append(x + y)
%o x, y = f(x, y)
%o print(res)
%K nonn,walk
%O 1,3
%A _Jens Ahlström_, Jun 05 2012
|