Question: for the n queens problem: how can i verify if a given configuration is avalid solution to the n queens problem. i am trying to
for the n queens problem:
how can i verify if a given configuration is avalid solution to the n queens problem. i am trying to check if a queen can attack another queen can attack another queen using haskell.
using the signature:
queens:: [Int] -> Bool
Strategies: A configuaration is a valid solution to the n-queen problem is all of the following:
All n queens are at the valid positions- that is row and column number they are at must be between 1 to n
No two queens are in the same column- this condition automatically satisfied since we can only put one number in each position of the list
No two queens are in the same row- this means making sure no two queens having the same row number
No two queens are on the same diagnol- this mean making sure:
no two queens having the same (row + column) value;and
no two queens have the same (row - column) value
If condition are met then the function should return true otherwise false.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
