Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Given an infinite chessboard represented as a 2D Cartesian plane. A knight is placed at the origin. What is the minimum number of moves it needs to reach a cell $(m,n)$? (Without loss of generality, we might as well assume that $m$ and $n$ are nonnegative integers.)

share|improve this question
3  
I'm not immediately sure, but it's easy to bound above. We know, for instance, that it should take less than say $m/2 + n/2 + 8$ moves. Is this a homework question or something? If so, please add the homework tag. –  mixedmath Feb 1 '12 at 19:32
    
You can solve it with dynamic programming but I'm not aware about availability of combinatorics proof, do you interested in algorithmic solution? –  Saeed Feb 1 '12 at 19:48
    
@Saeed Absolute value of m and n can be as large as one billion. So dynamic programming doesn't work I think. I'll appreciate any kind of solution and proof but as elementary as possible. –  f.nasim Feb 1 '12 at 20:15
    
@mixedmath I find it here actually. Does it belong to homework? –  f.nasim Feb 1 '12 at 20:17
3  
A lower bound for the number of moves is $(m+n)/3$, simply because a knight's move gains at most three squares in the north/east directions. If $n/2\le m\le 2n$ then the answer is presumably between $(m+n)/3$ and $(m+n)/3 + C$ for some small constant $C$. When one of $m$ and $n$ is much greater than the other, then the answer is probably closer to $\max\{m,n\}/2$. Note also that the exact answer might well depend a little on the value of $m+n\pmod 3$, since every knight's move changes this value by $\pm1$. –  Greg Martin Feb 1 '12 at 20:43
add comment

2 Answers

up vote 5 down vote accepted

After a bit of doodling, I have persuaded myself of the following:

To get to the origin in the fewest moves, always make the move (or one of the moves) that takes you closest to the origin, that is not to (0,1), or (2,2), or a reflection of one of these cells.

Perhaps after a bit more doodling, I'll come up with some kind of proof.

Updated to answer the question: If the above is true, then we can proceed as follows:

We may assume $m \ge n$. Then we repeat the move $(-2,-1)$ until we reach either the diagonal or the $x$-axis (I'm running the film backwards here, from $(m,n)$ to $(0,0)$).

If $m \ge 2n$, this takes $n$ moves, and ends up at $(m-2n,0)$.
If $m \le 2n$, this takes $m-n$ moves, and ends up at $(2n-m,2n-m)$.

So we only need to know how many moves are required from the diagonal or the $x$-axis.

For the diagonal, the number of moves to get from $(x,x)$ to the origin is $$2\lfloor \frac{x+2}{3}\rfloor $$ except for the anomalous point $(2,2)$, which requires 4 moves, not 2. But unless our starting point was $(2,2)$, we can ignore this anomaly $-$ coming from point $(4,3)$, we don't move to $(2,2)$, but to $(3,1)$, which requires 2 moves.

For the $x$-axis, the number of moves required to get from $(x,0)$ to the origin is $$x - 2\lfloor\frac{x}{4}\rfloor$$

except for the anomalous point $(1,0)$, which requires 3 moves, not 1. But unless our starting point was $(1,0)$, we can ignore this anomaly $-$ coming from point $(3,1)$, we don't move to $(1,0)$, but to $(1,2)$, which requires 1 move.

From this, it is easy to construct an explicit formula, if that's what you want; you only have to treat the starting points $(2,2)$ and $(1,0)$ as special cases.

share|improve this answer
    
Could you elaborate these two arguments: > the number of moves to get from $(x,x)$ to the origin is $2\lfloor \frac{x+2}{3} \rfloor$ and > the number of moves from $(x,0)$ to origin is $x - 2\lfloor \frac{x}{4} \rfloor$ –  f.nasim Feb 2 '12 at 9:59
1  
It takes 2 moves to get from $(x+3,x+3)$ to $(x,x)$, or from $(x+4,0)$ to $(x,0)$. This explains the factor of 2, and the denominators 3 and 4. To adjust it to the exact form, look at the values near the origin, which you can work out by hand. –  TonyK Feb 2 '12 at 11:49
add comment

The answers are tabulated here at the Online Encyclopedia of Integer Sequences. A formula is also given there, but it has a recursive component: for $m$ and $n$ at least 2, it gives $$T(m,n)=1+\min(T(m-2,n-1),T(m-1,n-2))$$ You could work on turning that into a closed form.

share|improve this answer
    
That's just dynamic programming. For $m,n$ in the region of a billion, it's not practical. –  TonyK Feb 1 '12 at 23:16
    
I'm aware that the formula I quoted is not practical for large $m,n$, which is why I encouraged OP to work on getting a closed form out of it. –  Gerry Myerson Feb 1 '12 at 23:30
    
Dynamic programming was already mentioned (and dismissed) in the early comments to the OP. As for a closed form, have a look at my answer :-) –  TonyK Feb 1 '12 at 23:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.