Knight's tour solver. 19th IOCCC. Best Small Program
Can you place a knight on a chessboard and make it
to visit the 64 squares without repeating them?
If not, this program solves the puzzle, just
run it with an argument giving initial position.
prog 11 (start is A8)
prog 18 (start is H8)
prog 81 (start is A1)
prog 88 (start is H1)
prog 44 (start is D5)
It will print move order. The algorithm is so
simple that you can read it on the source code,
at the first glance it can appear checkered :-)
but don't dismail, jar, jar.
Here is the source code, written in C language:
char *e,t [366 ],*f
,*g, *h,* i;d, m ;
main (c,b) char **b;{
for( ;d[t] =d%3 ?60<d
&300 >d&6 <d % 30?0
:32: d%30 ?32: 10 ,
366> ++d;) ;for (g=3*
atoi (*++ b) + 34+t;
i=f= "\1" "\7" "(d"
"\177" "yX" "\34" ,e=g
; ) for( *e++ =++m/
10 + 48,g =c=0 ,*e =
48+m %10; h=e- 65+*
i,d= *h,* i++; f-=8
,g=d <c?c =d,h: g)for
(; d -=!! h[*f ++-64
],*f ;) ; puts (t);}
Decoding this program can be a real challenge for any C
language student.
How to compile it
First, download the source code from
here.
To compile use:
cc toledo1.c -o toledo1
Useful links
Last modified: Feb/11/2013