Answer : Following the suggestion of @BarakManos: Step 1: Construct a graph where each square of the chess board is a vertex. Step 2: Place an edge between vertices exactly when there is a single knight-move from one square to another. Step 3: Dijkstra's algorithm is an algorithm to find the length of a path between two vertices (squares). It is very classical in graph theory, data structures, and algorithms. There's actually few restrictions that are due to the edge of the board. One of these (or the only case) is moving from A1 to B2 for example. Normally it would take two moves to move one step diagonally, but here that solution would move you of board. Instead you would have to move to C2 or B3 first and then it's a move one step along file or row which is three steps. Then it should be quite straight forward to just testing for solutions. The reason you don't get that many restrictions from the edges is that there will be similar solutions by symmetry...