N Queens Puzzle and Solution

N Queens Puzzle and graphical solution for an N*N chessboard.

You are now following this Submission

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 (2026). N Queens Puzzle and Solution (https://www.mathworks.com/matlabcentral/fileexchange/73566-n-queens-puzzle-and-solution), MATLAB Central File Exchange. Retrieved .

Categories

Find more on Read, Write, and Modify Image in Help Center and MATLAB Answers

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0