A variation of the Classical N-Queen Puzzle

I’ve always loved the classical N-Queen puzzle. The goal is to place eight chess queens on an 8×8 chessboard so that no two queens attack each other.

Here’s one solution (92 in total):

Some time ago, a clever friend asked me if the number of solutions would be greater or lower if the goal was to place 7 queens instead of 8.

– “Greater, of course” – I replied.
– “And if you had to place 6?”

Then I realized that the number of possible solutions would peak at some point and then it would decrease until it hits 64 (the number of squares = the number of solutions if the goal was to place only one queen).

The highest number of solutions occurs when the goal is to place 5 queens.

I had a lot of fun coding the solution, using recursion and backtracking.

Here’s the source code on GitHub.

Daniel Rabinovich