Problem 306. Eight Queens Solution Checker
Solution Stats
Problem Comments
-
2 Comments
This question is kind of a duplicate of Ned's N-queens checker: http://www.mathworks.com/matlabcentral/cody/problems/113-n-queens-checker
Oops, I didn't know about that one!
Solution Comments
-
1 Comment
No loops, no conditions: Beautiful!
-
1 Comment
will fail for any two or more queens on the anti diagonal
-
1 Comment
Why the first test case fails? It passes in the matlab.
-
1 Comment
This is a flawed solution. For example, when the queen positions are {a2, b4, c2, c6, d8, e3, f1, g7, h5} (which is the same as the image in the description, but with a 9th queen added at c2), this code would return 'True' while the correct answer is obviously 'False'.
-
3 Comments
The beauty of this solution is that you can use it for any other side board (e.g., isEightQueensSolution([1 0; 0 1]) ).
how can i view this solution, also, can you please explain to me why the tenth test case is false, i dont think it is wrong.
Alex, the tenth case case is false because there are only seven queens on the board.
-
5 Comments
Doesn't this kind of trick get boring after a while?
actually, this is the first time i've used it without essentially copying Alfonso's code, so it's still new and fresh for me =P
Can someone explain to me how this function works (even if it is a trick)? I'm trying to parse through the code, but how it works isn't clear to me.
the sparse function places the values (third input) into the row and column specified, 1st and second inputs respectively. if there are any overlapping coordinates then it sums them, so I created a matrix that, when fed into sparse, would sum the rows, sum the columns, and sum the diagonals in each direction. Then I Cody-fied it (teehee) by changing these indices into a string of characters, which Cody sizes as small, and subtracting a base character from it. does that make sense now?
it might make more sense to look at one of my other solutions that uses the str2num function instead of the letter thing...
-
1 Comment
I think you also need to check the diagonals of fliplr(a). The tests did not include multiple queens on any of those diagonals.
Problem Recent Solvers164
Suggested Problems
-
Remove all the words that end with "ain"
1861 Solvers
-
272 Solvers
-
1488 Solvers
-
272 Solvers
-
There are 10 types of people in the world
795 Solvers
More from this Author5
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!