Program | KNIGHT.C, KNIGHT.CPP, KNIGHT.PAS |
The chessboard is an 8 by 8 grid of squares. For the purpose of this problem consider the rows of the chessboard to be numbered from 1 to 8 starting at the top and moving down, and the columns to be numbered from 1 to 8 starting at the left and moving right. Board positions will be identified by (row, column) ordered pairs.
The knight is a chess piece capable of moving exactly two squares in one direction and then one square perpendicularly. The figure on the left below shows the possible moves for a knight located on the board at (4,5). Assuming the board is empty except for a knight, the problem is to determine the minimum number of moves required to move from point A to point B on the board. The figure on the right below shows one possibility for the minimum required three moves to move a knight from (4,5) to (4,4).
Sample Input
2
5 5 4 5
3 1 3 8
Sample Output
3
5