A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once. If the knight ends on a square that is one knight's move from the beginning square the tour is closed, otherwise it is open.


Find a knight's tour on a chess board with n × m squares.


The earliest known reference to the knight's tour problem dates back to the 9th century AD.

Number of tours

The number of directed open tours are:
Board #
1x1 1
2x2 0
3x3 0
4x4 0
5x5 1728
6x6 6637920
7x7 165575218320
8x8 19591828170979904