- The Eight Queens Challenge is a classic
programming puzzle, one that the C language
is more than capable of handling.
No fancy graphics, no extra libraries,
just pure programming proficiency.
Solutions vary, and because C can be
an extremely cryptic language,
quite a few of the code samples you may find
take great pains to be nearly unreadable.
I suppose there's a charm in that,
and I'll discuss specifics in a later movie.
For now, my approach was to write
a program called "nqueens".
The name comes from the "n" in number,
meaning that the program can handle
more than one size chess board.
That's because, as you'll discover should you attempt
your own solution, once you get a solution
for an 8x8 chessboard, you can easily change
the number of squares and run the solution
on any size board.
The interface is simple.
Type "./nqueens" and the code searches for solutions
on a standard 64-square or 8x8 board.
Here you see that 92 solutions are found,
which is the proper number.
If you wanna find solutions for a different size board,
specify that value as the first argument.
Here you see 724 solutions for a 10x10 board.
Larger values can be specified,
although the bigger the number
the longer it takes the code to run.
The board option displays a chessboard for each solution,
with the queens' location marked by a "Q".
The brief option displays a standard row column output
with the letters A through whatever
representing the columns left to right,
then numbers representing the rows bottom to top.
I chose this presentation,
not because it's official or anything,
but the chessboard in my house uses this type
of lettering scheme.
A help switch is also available,
which gives you the commands options.
In the next movie, I'll uncover my initial attempts
to find a solution, and why they failed.