The N-Queens problem is a classic example for a constraint satisfaction problem: given a chessboard of size NxN, place N queens on the board such that none of them can hit any other in one move.

There are 12 distinct solutions for the 8-queens problem - two solutions are not distinct if you can obtain one from another by rotating or flipping the chessboard. Clearly, there are no solutions for the 2-queens and 3-queens problems.

There’s a nice on-line N-Queens demo at, where you can set N and let a Java applet find the solutions for you.

At the time of writing, Google returns about 12,000 hits when searching for ‘n-queens’, and there are dozens – if not more - of methods and algorithms for finding solutions.