Simple solution for the n-queens problem in Java using recursive backtracking. The program takes in a single numeric argument 'n' - this is the size of the chess board (n x n) and the number of queens that are being placed on the chess board. All possible configurations of queen placement are found and printed out.
java -jar nqueens-0.1.0.jar <n>
~/shivan/NQueens (master) $ java -jar nqueens-0.1.0.jar 4
| |Q| | |
| | | |Q|
|Q| | | |
| | |Q| |
| | |Q| |
|Q| | | |
| | | |Q|
| |Q| | |
There are 2 solutions to 4-queens problem
This project uses Gradle.
./gradlew build
The .jar
file is generated in build/libs/
.
./gradlew test