N Queens Puzzle and Solution
N Queens Puzzle is the problem of placing N queens on a chessboard in such a way that none of the queens threaten each other: only one queen in each row, column and diagonal. The problem was first put forward in 1848 just looking at 8 queens and solved by 1850 where the idea of the N queens on an N*N board was brought forward as an extension to the problem.
This code creates an N*N chessboard using the Chessboard.m function. The Queens.m script then solves the problem by placing the queens in unique rows and columns. The code then checks to see if any queens have been placed in the same diagonal and restarts if that is the case, choosing a new placement for all queens. This is a light brute forcing of a solution.
Cite As
Martin Thomas (2024). N Queens Puzzle and Solution (https://www.mathworks.com/matlabcentral/fileexchange/73566-n-queens-puzzle-and-solution), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |