Problem 44347. Ned's queens
A tribute to Cody's five-year anniversary should also celebrate the people behind Cody, and in this particular case, our illustrious Quizmaster, Ned Gulley.
The N-Queens problem (N stands for Ned, of course) is a well known computing challenge. If you are unfamiliar with this problem, refer to Problem 113, incidentally written by... You guessed it.
This problem is the real deal. Given a positive integer, n, representing the number of queens and the size of the board, return the number of possible solutions, s, and a list of the solutions, q.
q shall be an array with s rows and n columns, such that each row represents one solution. The column indeces of q shall represent the column indeces of the positions of the queens in the respective solution, while the values of the array elements shall represent the row indeces of the positions of the queens in the respective solution. q does not have to be sorted.
Note: All symmetries/rotations count as individual solutions.
Example:
Input: n = 4
Output: s = 2, q = [2 4 1 3;3 1 4 2]
Solution Stats
Problem Comments
-
1 Comment
This was a fun problem, but I think lookup table solutions are possible given the way the way the test suite is configured. Maybe you could add a string parser to see if the test suite correct solutions are included in the answer code?
Solution Comments
Show commentsProblem Recent Solvers91
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15745 Solvers
-
1340 Solvers
-
1054 Solvers
-
Create an n-by-n null matrix and fill with ones certain positions
682 Solvers
-
(Linear) Recurrence Equations - Generalised Fibonacci-like sequences
401 Solvers
More from this Author45
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!