Skip to content

Solving the N Queens puzzle using backtracking algorithm

License

Notifications You must be signed in to change notification settings

InvincibleJuggernaut/N-Queens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

N-Queens

Introduction

N queens is a famous puzzle of placing N queens in a NxN gridboard. The puzzle originates from the Eight queens puzzle in chess.

To better understand the problem, first we need to understand a queen's moves in chess.

In some ways, the queen can be thought of as the most powerful piece on the chessboard. The above image shows the moves avilable to the queen in the next move. It can move along the four main directions as well as diagonally; not limited by the number of jumps. Therefore, the challenge is to place 8 queens in a 8x8 chessboard such that no queen can attack another.

This program finds out all the possible solutions for a given dimension of the board.

One such solution is given below :

This is just one possible solution to the above problem. There are 12 unique solutions to 8x8 puzzle. These solutions can be rotated to obtain even more solutions. In total, this would amount to 92 solutions for a chessboard.

Technology

  • Python 3.6.9

Cloning

Open Terminal in your preferred directory and type :

git clone https://github.com/InvincibleJuggernaut/N-Queens.git

Usage

Open the repository and open Terminal to run the program using :

python3 n_queens.py

License

MIT License

Releases

No releases published

Packages

No packages published

Languages