Question: 6 . N queens problem: ( 2 0 Points ) Write a tail - recursive prolog program for the n queens problem. The objective is
N queens problem: Points
Write a tailrecursive prolog program for the n queens problem. The objective is to place n queens
on a chessboard of size times so that no two queens are attacking each other; ie no two queens
are in the same row, the same column, or on the same diagonal.
Note: All the recursive predicates in this program must be tailrecursive. Represent the positions
of the queens as a list of numbers N For example: When N the list Qs with the positions
would be This means that the queen in the first column is in row the queen in
the second column is in row etc. The goal predicate will take the form:
queensN Qs
where N the number of queens
Qs solution to the problem
Sample Run:
queens Qs
Qs ;
Qs ;
Qs ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
