This Scala application solves the N-Queens problem using recursion and backtracking. It employs functional programming principles such as immutability, pure functions, and higher-order functions. The application allows users to specify board dimensions, the number of queens, and whether to display all possible solutions or just the count.
- Solves the N-Queens problem for any board size and number of queens.
- Utilizes recursion and backtracking for the solution.
- Implements functional programming principles.
- Command-line interface for setting board dimensions and number of queens.
- Option to display all solutions or just the count of solutions.
- Scala (version 2.12 or later)
- Java JDK (version 8 or later)
To compile and run the program, use the following commands:
scala main.scala [options]
--height <height>
: Specifies the height of the board. Default is12
.--length <length>
: Specifies the length of the board. Default is20
.--queens <number>
: Specifies the number of queens. Default is3
.--show-board
: If present, the program will print out all possible board configurations. Otherwise, it will only print the count of solutions.
- Run with default values:
scala main.scala
- Specify custom board dimensions and number of queens:
scala main.scala --height 8 --length 8 --queens 8
- Display all possible board configurations:
scala main.scala --height 8 --length 8 --queens 8 --show-board