- Place N queens on said N×N chessboard so that no two queens threaten each other.
- The Queen can move in it's line or row, or diagonally, any number of squares
This is my solution for this problem/puzzle.
This algorithm shows only one solution by time runned.
- Made using Javascript.
In this repository there are many solutions in different languages, the best solution is the one in JavaScript due to the use of HashSet tables, and it´s has.()
method with complexity O(1).
To install this repository correctly follow the next steps.
-
First of all, in the terminal put the next code to clone this repository:
git clone https://github.com/Rafael-Anguiano/N-Queens.git cd N-Queens/
-
The next step is to make sure you have a way to run this code, in this situation we will use Node.js for JavasScript and/or Python, if you don't have it installed, we recommend you to download it.
-
Once you have installed a runner, you are ready to start simulating and editing some code. To run this app use the next command in the terminal (Be sure you are in the directory of the language solution you want to run).
- For JavaScript:
node index.js <boardSize1> <boardSize2> <boarSize...>
- For Python:
python main.py <boardSize1> <boardSize2> <boarSize...>
- There are many different ways to solve this puzzle with the same input.
- The algorithm have a random percentage, this means you could receive a different solution each time.
- The Queen can move in its line or row, or diagonally, any number of squares.
Rafael de Jesús Anguiano Suárez del Real (April 2022)