Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.5%) to scientific vocabulary
Keywords
Repository
N-Queens Solver.
Basic Info
Statistics
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 3
- Releases: 3
Topics
Metadata Files
README.md
Overview
The N-Queens problem is a classic challenge often encountered in programming interviews and academic settings. The challenge is to place N queens on an N×N chessboard such that no two queens threaten each other. This means that no two queens can share the same row, column, or diagonal.
Problem Statement
Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answers in any order.
Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' indicates a queen and '.' indicates an empty space.
Example
For n = 4, the possible solutions are:
``` [ [".Q..", // Solution 1 "...Q", "Q...", "..Q."],
["..Q.", // Solution 2 "Q...", "...Q", ".Q.."] ] ```
Approach and Algorithms
Backtracking Algorithm
The most common approach to solve the N-Queens problem is using backtracking. The backtracking algorithm incrementally builds candidates to the solution and abandons a candidate as soon as it determines that the candidate cannot possibly lead to a valid solution.
Steps:
1. Initialize the Board: Start with an empty N×N board.
2. Place the Queen: Try to place the queen in the first row and proceed to place subsequent queens.
3. Check Validity: For each queen placement, check if it conflicts with already placed queens.
4. Backtrack if Necessary: If placing a queen leads to no solution, remove the queen (backtrack) and try the next position.
5. Store the Solution: If a valid configuration is found (N queens placed), store the board configuration.
6. Repeat: Continue this process until all possible configurations have been tried.
Challenges
Board Representation
The board can be represented using a 2D list where each cell is either 'Q' or '.'.
Checking Conflicts
Efficiently checking for conflicts is crucial:
Row Check: Ensuring no other queens are in the same row.Column Check: Ensuring no other queens are in the same column.Diagonal Check: Ensuring no other queens are on the same diagonal.
Optimization
Using sets to track occupied columns and diagonals can speed up the conflict check process.
Concurrency with ThreadPoolExecutor
To optimize solving the problem for larger n, the solution leverages concurrency with ThreadPoolExecutor:
- Each thread starts solving the problem for a different column in the first row.
- This parallel approach can significantly reduce the time to find all solutions.
Our Solution
This solution came frome one of our Free Friday Challenges, where we pick random interview challenges during our downtime to write solutions to.
Installation
pip install wolfsoftware.NQueens
Usage
``` usage: nqueens [-h] [-v] [-V] [board_size]
See solutions to the NQueens problem.
positional arguments: board_size Size of the board (default is 8 for the Eight Queens puzzle) (default: 8)
flags: -h, --help Show this help message and exit -v, --verbose Enable verbose output - show the actual boards (default: False) -V, --version Show program's version number and exit.
The N Queens puzzle is the problem of placing N chess queens on an N×N chessboard so that no two queens threaten each other. ```
Summary
The N-Queens problem is a fascinating and complex challenge that requires a deep understanding of recursion, backtracking, and optimization techniques. By leveraging multi-threading, this implementation efficiently finds all possible solutions for a given board size. Understanding and implementing the N-Queens problem is a valuable exercise for improving problem-solving skills and algorithmic thinking.
Owner
- Name: The Grot Shop
- Login: TheGrotShop
- Kind: organization
- Email: github@wolfsoftware.com
- Location: United Kingdom
- Website: https://wolfsoftware.com
- Twitter: wolfsoftware
- Repositories: 1
- Profile: https://github.com/TheGrotShop
Grot has lots of things that aren’t of any use, some of them are red, some of them are green and some of them are puce.
Citation (CITATION.cff)
cff-version: 1.2.0
message: If you use this software, please cite it using these metadata.
title: NQueens Solver
abstract: A simple NQueens solver.
type: software
version: 0.1.1
date-released: 2024-06-26
repository-code: https://github.com/TheGrotShop/NQueens-package
keywords:
- "Wolf Software"
- "Software"
license: MIT
authors:
- family-names: "Wolf"
orcid: "https://orcid.org/0009-0007-0983-2072"
GitHub Events
Total
- Watch event: 1
- Delete event: 76
- Issue comment event: 152
- Push event: 120
- Pull request review event: 111
- Pull request event: 153
- Create event: 80
Last Year
- Watch event: 1
- Delete event: 76
- Issue comment event: 152
- Push event: 120
- Pull request review event: 111
- Pull request event: 153
- Create event: 80
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 60
- Average time to close issues: N/A
- Average time to close pull requests: 5 days
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 1.58
- Merged pull requests: 34
- Bot issues: 0
- Bot pull requests: 60
Past Year
- Issues: 0
- Pull requests: 60
- Average time to close issues: N/A
- Average time to close pull requests: 5 days
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 1.58
- Merged pull requests: 34
- Bot issues: 0
- Bot pull requests: 60
Top Authors
Issue Authors
Pull Request Authors
- dependabot[bot] (119)
- TGWolf (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 10 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 2
- Total maintainers: 1
pypi.org: wolfsoftware.nqueens
A simple solution for the N Queens problem.
- Homepage: https://github.com/TheGrotShop/NQueens-package
- Documentation: https://github.com/TheGrotShop/NQueens-package
- License: MIT License
-
Latest release: 0.1.1
published over 1 year ago
Rankings
Maintainers (1)
Dependencies
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- citation-file-format/cffconvert-github-action 4cf11baa70a673bfdf9dad0acc7ee33b3f4b6084 composite
- ruby/setup-ruby ff740bc00a01b3a50fffc55a1071b1060eeae9dc composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- github/codeql-action/analyze a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- github/codeql-action/autobuild a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- github/codeql-action/init a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- github/codeql-action/analyze a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- github/codeql-action/autobuild a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- github/codeql-action/init a57c67b89589d2d13d5ac85a9fc4679c7539f94c composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- Mattraks/delete-workflow-runs 39f0bbed25d76b34de5594dceab824811479e5de composite
- dependabot/fetch-metadata 5e5f99653a5b510e8555840e80cbf1514ad4af38 composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- actions/setup-node 60edb5dd545a775178f52524783378180af0d1f8 composite
- ruby/setup-ruby ff740bc00a01b3a50fffc55a1071b1060eeae9dc composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- Bullrich/generate-release-changelog 6b60f004b4bf12ff271603dc32dbd261965ad2f2 composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
- softprops/action-gh-release 69320dbe05506a9a39fc8ae11030b214ec2d1f87 composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- Bullrich/generate-release-changelog 6b60f004b4bf12ff271603dc32dbd261965ad2f2 composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
- softprops/action-gh-release 69320dbe05506a9a39fc8ae11030b214ec2d1f87 composite
- actions/first-interaction 34f15e814fe48ac9312ccf29db4e74fa767cbab7 composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- otto-de/purge-deprecated-workflow-runs 31a4e821d43e9a354cbd65845922c76e4b4b3633 composite
- ActionsToolbox/get-language-versions-action 446919617fd774095b5dd3ed71c39dd3fd0d8f4f composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- actions/setup-go cdcb36043654635271a94b9a6d1392de5bb323a7 composite
- actions/setup-python 82c7e631bb3cdc910f68e0081d67478d79c6982d composite
- actions/checkout 692973e3d937129bcbf40652eb9f2f61becf3332 composite
- zgosalvez/github-actions-ensure-sha-pinned-actions 76d1d8e0b075d7190b5d59b86da91c7bdbcc99b2 composite
- Gamesight/slack-workflow-status 68bf00d0dbdbcb206c278399aa1ef6c14f74347a composite
- actions/stale 28ca1036281a5e5922ead5184a1bbf96e5fc984e composite
- setuptools ==70.0.0
- wolfsoftware.notify ==0.1.0
- setuptools ==70.2.0 development