[math-fun] Knight Distance
This formula works: kd = Function[{ox, oy}, Module[{x = Max[Abs[ox], Abs[oy]], y = Min[Abs[ox], Abs[oy]], p = 0}, p = If[3 x < 2 (x + y), (x + y + 1)/3, (x + 1)/2]; If[Mod[x + y, 2] == 0, p = 2 Floor[(p + 1)/2], p = 2 Floor[p/2] + 1]; If[x == 1 && y == 0, p = 3]; If[x == 2 && y == 2, p = 4]; p]]; Proof: It suffices to verify that kd[0, 0] = 0 and kd[x, y] = 1 + Min[kd[x + 1, y + 2], kd[x + 2, y + 1], ..., kd[x - 2, y - 1]], in which case we are done by induction on the value of kd[x, y]. Both of these are absolutely trivial to verify, although the latter is a messy case-bash (having to special-case squares near the lines 2|x| = |y| and 2|y| = |x|). Sincerely, Adam P. Goucher --uh, well, that was what I was saying, but the devil is in the details ("nasty case bash") i.e. the sentence you used to avoid actually proving it. Meanwhile, E.Clark's tip led me to find the "Encyclopedia of Distances" by Michel Marie Deza, Elena Deza, published by Springer 2009. Amazingly enough, on page 336 it says: The Knight distance... is 3 if (M,m)=(1,0); is 4 if (M,m)=(2,2); otherwise equals max( ceiling(M/2), ceiling((M+m)/3)) + (M+m) - max(ceiling(M/2), ceiling(((M+m)/3)) mod 2 where M>=m>=0. They then define a "(p,q) super knight" or "(p,q)-leaper" which leaps p squares in x or y direction the q squares in orthogonal direction; the usual knight is a (2,1) leaper. For various (p,q) these have been called "Wazir, Ferz, camel, giraffe"... They then say the metric for this has been studied by PP Das & J Mukherjee: Pattern Recognition Letters 11 (1990) 601-604.
Meanwhile, E.Clark's tip led me to find the "Encyclopedia of Distances" by Michel Marie Deza, Elena Deza, published by Springer 2009. Amazingly enough, on page 336 it says:
The Knight distance... is 3 if (M,m)=(1,0); is 4 if (M,m)=(2,2); otherwise equals max( ceiling(M/2), ceiling((M+m)/3)) + (M+m) - max(ceiling(M/2), ceiling(((M+m)/3)) mod 2 where M>=m>=0.
--Unfortunately the Encyclopedia's formula is wrong since it thinks KnightDist(3,0) = 5, whereas actually it is 3. But this was merely a typo, which we can correct by inserting parentheses []: CORRECTED: The Knight distance... is 3 if (M,m)=(1,0); is 4 if (M,m)=(2,2); otherwise equals max( ceiling(M/2), ceiling((M+m)/3)) + [(M+m) - max(ceiling(M/2), ceiling(((M+m)/3))] mod 2 where M>=m>=0.
participants (2)
-
Dan Asimov -
Warren D Smith