Question: I am writing a haskell function queens with the following signature: queens::[Int]-->Bool. As a verfication problem. This function takes a list of size n, which

I am writing a haskell function queens with the following signature: queens::[Int]-->Bool. As a verfication problem.

This function takes a list of size n, which represents a configuration of placing n queens on an n-by-n chess board, and verifies if it is a valid solution of the n-queen problem, by returning a Boolean value of True or False. Please note that the value of n is not given, but this value can be inferred from the length of input list.

The values in the input list are the row numbers of the queens in each column. For example, the input list [2,4,1,3] represents a configuration of placing 4 queens on a 4-by-4 chess board, one in each column. The queen in the first column is placed at row 2; the queen in the second column is placed at row 4; and so on. To make thing a little more interesting, we make the column numbers and row numbers ranging from 1 to n. Place note that in Haskell, the index of a list of length n ranges from 0 to n-1.

Strategies:

A configuration is a valid solution to the n-queen problem is all the following is satisfied: All n queens are at valid positions that is, the row and column numbers they are at must be between 1 to n. No two queens are in the same column this condition is 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 diagonal this means making sure: o no two queens having the same (row + column) value; and o no two queens having the same (row column) value.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!