This project is a Python-based N-Queens Problem Solver developed as part of the Codveda Technologies Python Development Internship.
The program uses the Backtracking algorithm to place N queens on an N × N chessboard so that no two queens attack each other. It validates user input, finds all possible solutions, and displays the total number of valid arrangements. Users can also choose to view every solution in a simple console-based board format.
- Solve the N-Queens problem using the Backtracking algorithm.
- Validate user input for the board size (N).
- Generate all valid queen arrangements.
- Display the total number of possible solutions.
- Print each solution in a readable chessboard format.
- Python
- Backtracking Algorithm
- Recursion
- Visual Studio Code
- Accepts any valid board size (N ≥ 1).
- Finds all possible solutions efficiently.
- Displays the total number of solutions.
- Option to print every valid board configuration.
- User-friendly command-line interface.
-
Make sure Python 3 is installed on your system.
-
Open the project folder in the terminal.
-
Run the program:
python n_queens_solver.pyor
python3 n_queens_solver.py-
Enter the board size (N) when prompted.
-
Choose whether to display all valid solutions.
- The program uses the Backtracking algorithm to solve the N-Queens problem.
- The number of solutions increases significantly as the value of N becomes larger.
- For large values of N, the program may take more time to generate all solutions.
- Accepts the board size (N) from the user.
- Validates the user input.
- Displays the total number of valid solutions.
- Prints all possible board arrangements if requested.
- Represents queens using Q and empty spaces using .