Prolog code:

Video: |

This solution uses CLP(ℤ) constraints to model the problem. In particular, the

- one
*node*per board position - one
*edge*between those nodes that can be reached via knight's moves.

You need Scryer Prolog. Start it with

$ scryer-prolog knight.pl

Example queries that you can try:

?- n_tour(N, Ts), maplist(label, Ts). ?- n_tour(N, Ts), maplist(label, Ts), print_tour(Ts).To visualize solutions with Ghostscript, use:

$ scryer-prolog -g "show(6,[ff])" knight.pl | \ gs -dNOPROMPT -g510x510 -r72 -q

Sample solutions for N = 6, 8, 12, 16:

Challenges: Find solutions for large boards. Find good labeling and allocation strategies. ...

More about Prolog: