This program produces solutions for a nested semimagic knight's tour. This is a knight's tour on an 8x8 board whose numbered steps produce a semimagic square and whose four 4x4 quadrants are each themselves semimagic squares.
The problem appeared in a puzzle called "Knight Errant" in The Ultimate Book of Number Puzzles by Kenneth Kelsey. In it, Kelsey states he could only find four solutions (ignoring rotations and reflections), of which he presents incomplete versions in the book inviting the reader to complete them. This program shows there are four more solutions.
More information about the problem and the algorithm design is at https://greem.co.uk/knighterrant/
The knighterrant program has been compiled on Linux with GCC and libpthread.
Assuming you have gcc, glibc and libpthread-dev installed, you can build the program using make
:
make knighterrant
The knighterrant
binary will be written to the same directory as the source.
In addition, you can make
the binaries ketest5
and ketest6
, which count the number of general knight's tours on a 5x5 and 6x6 board for testing purposes, and knighterrant-any-start-and-end
, which solves the same problem without imposing restrictions on where the tour can start and end.
You can run the program without arguments:
./knighterrant
By default it will use four worker threads. If you like, you can increase this with the -t
option:
# Run with 12 worker threads
./knighterrant -t 12
The program finds eight solutions, which are written to standard output and formatted with the Unicode box drawing characters:
Found tour #1...
ββββ¬βββ¬βββ¬βββ¬βββ¬βββ¬βββ¬βββ
β 1β48β31β50β33β16β63β18β
ββββΌβββΌβββΌβββΌβββΌβββΌβββΌβββ€
β30β51β46β 3β62β19β14β35β
ββββΌβββΌβββΌβββΌβββΌβββΌβββΌβββ€
β47β 2β49β32β15β34β17β64β
ββββΌβββΌβββΌβββΌβββΌβββΌβββΌβββ€
β52β29β 4β45β20β61β36β13β
ββββΌβββΌβββΌβββΌβββΌβββΌβββΌβββ€
β 5β44β25β56β 9β40β21β60β
ββββΌβββΌβββΌβββΌβββΌβββΌβββΌβββ€
β28β53β 8β41β24β57β12β37β
ββββΌβββΌβββΌβββΌβββΌβββΌβββΌβββ€
β43β 6β55β26β39β10β59β22β
ββββΌβββΌβββΌβββΌβββΌβββΌβββΌβββ€
β54β27β42β 7β58β23β38β11β
ββββ΄βββ΄βββ΄βββ΄βββ΄βββ΄βββ΄βββ