Skip to content

The aim of N-Queens Problem is to place N queens on an N x N chessboard, in a way so that no queen is in conflict with the others.

Notifications You must be signed in to change notification settings

jaiswalchitransh/N-Queens-Problem-using-Backtracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

N-Queens Problem using Backtracking

Table of Contents

Project Overview

This Python script solves the N-Queens problem using a backtracking algorithm. The goal of the N-Queens problem is to place N queens on an N×N chessboard such that no two queens threaten each other. The script generates all possible solutions for placing the queens on the board and can handle boards of size N where N is greater than or equal to 4. It employs a depth-first search approach to explore possible placements of queens and backtracks when a conflict is detected.

The script accepts the size of the chessboard from the user, then calculates and displays one of the possible solutions randomly, along with the total number of solutions.

Installation

This project requires Python 3.12.1 or later. To set up the project:

  1. Ensure Python 3.12.1 or a later version is installed on your system. You can download Python from python.org.

  2. Clone or download the repository to your local machine.

       https://github.com/jaiswalchitransh/N-Queens-Problem-using-Backtracking.git
    
  3. Open the project in your preferred Python environment (e.g., IDE or terminal).

  4. Run the script (n-queens.py) and observe the output.

Usage

Run the script:

     python n-queens.py

Follow the on-screen prompts to input the size of the chessboard. The script will then compute and display one of the solutions to the N-Queens problem and the total number of possible solutions.

Features

  • Backtracking Algorithm: Efficiently finds all solutions by exploring possible placements of queens.
  • Random Solution Display: Randomly selects and prints one of the valid solutions.
  • Solution Count: Outputs the total number of solutions for the given board size.

Contribution

I, Chitransh Jaiswal developed this Project Individually. I was responsible for all aspects of the project, including design, development, testing, and documentation. Contributions to improve the efficiency, readability, or functionality of the code are welcome. To contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Make your changes.
  4. Commit your changes (git commit -am 'Add some feature').
  5. Push to the branch (git push origin feature/your-feature).
  6. Create a new Pull Request.

Please ensure your contributions adhere to the coding standards and follow the existing style and structure.


Thank you for your interest in the N-Queens problem solver. Explore the solutions to this classic problem and contribute to further enhancements!

About

The aim of N-Queens Problem is to place N queens on an N x N chessboard, in a way so that no queen is in conflict with the others.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages