N Queens Puzzle and Solution

N Queens Puzzle and graphical solution for an N*N chessboard.
138 Downloads
Updated 5 Dec 2019

View License

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
Created with R2019b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Read, Write, and Modify Image in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0