This code helps you to understand the NQueen problem
The example code is in Java (version 1.8 or higher will work).
The N queens puzzle is the problem of placing eight chess queens on an nรn chessboard so that no two queens threaten each other. Thus, a solution requires that no two queens share the same row, column, or diagonal. Chess composer Max Bezzel published the eight queens puzzle in 1848. Franz Nauck published the first solutions in 1850.[2] Nauck also extended the puzzle to the n queens problem, with n queens on a chessboard of n ร n squares.
Since then, many mathematicians, including Carl Friedrich Gauss, have worked on both the eight queens puzzle and its generalized n-queens version. In 1874, S. Gunther proposed a method using determinants to find solutions.[2] J.W.L. Glaisher refined Gunther's approach.
In 1972, Edsger Dijkstra used this problem to illustrate the power of what he called structured programming. He published a highly detailed description of a depth-first backtracking algorithm.
For more information, see
To compile the code, simply run the javac NQueen.java
.
To run the code, type java NQueen
javac NQueen.java
java NQueen