Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Place N queens on said N×N chessboard so that no two queens threaten each other.

NotificationsYou must be signed in to change notification settings

Rafael-Anguiano/N-Queens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Problem:

  • Place N queens on said N×N chessboard so thatno two queens threaten each other.
  • TheQueen can move in it's line or row, or diagonally, any number of squares

N-Queens Solution ExampleQueen Movement

Description

This is my solution for this problem/puzzle.

This algorithm shows only one solution by time runned.

  • Made using Javascript.

Solution Explanation

In this repository there are many solutions in different languages, the best solution is the one inJavaScript due to the use of HashSet tables, and it´shas.() method with complexityO(1).


Installation

To install this repository correctly follow the next steps.

  1. First of all, in the terminal put the next code to clone this repository:

        git clone https://github.com/Rafael-Anguiano/N-Queens.gitcd N-Queens/
  2. The next step is to make sure you have a way to run this code, in this situation we will useNode.js forJavasScript and/orPython, if you don't have it installed, we recommend you to download it.

  3. 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 #"auto" data-snippet-clipboard-copy-content=" node index.js <boardSize1> <boardSize2> <boarSize...>">
          node index.js<boardSize1><boardSize2><boarSize...>
  • For Python:
    python main.py<boardSize1><boardSize2><boarSize...>

ScreenShots of the Results

Case FailedCase 1Case 4Case 8Case 10Case 26Case 45


Notes:

  • 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.

Developed By:

Rafael de Jesús Anguiano Suárez del Real (April 2022)

About

Place N queens on said N×N chessboard so that no two queens threaten each other.

Topics

Resources

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp