Question: Do the following in Python: In the eight queens problem, eight queens must be placed on a chessboard in such a way that no pair

Do the following in Python:

In the eight queens problem, eight queens must be placed on a chessboard in such a way that no pair of queens is currently threatening one another. One possible solution to the eight queens problem is this:

In any solution to the eight queens problem, all the empty squares on the chessboard are threatened by at least two queens. We refer to a square that is threatened by exactly two queens as safe. These squares are marked here in green:

For the given configuration of queens, there is only one way to put four kings on the safe squares such that no two kings are currently threatening one another:

With apologies to standard chess notation, we can describe the locations of the queens and kings on this board using the following two lists of coordinates: [(0, 2), (1, 5), (2, 3), (3, 1), (4, 7), (5, 4), (6, 6), (7, 0)] [(1, 7), (3, 0), (7, 1), (7, 3)]

For , an board and the following queen configuration: [(0, 1), (1, 9), (2, 7), (3, 5), (4, 3), (5, 12), (6, 10), (7, 13), (8, 11), (9, 6), (10, 4), (11, 2), (12, 0), (13, 8)]

Is it possible to find arrangement of kings. One such arrangement is [(0, 0), (1, 10), (2, 0), (4, 0), (4, 2), (9, 2), (9, 9), (11, 0), (11, 7), (11, 11), (13, 5), (13, 9), (13, 11), (13, 13)]

There are 41 possible arrangements of kings in total.

The goal: Find a placement of queens on an board such that no pair of queens threatens each other, and the number of different ways to place kings on the safe squares without any pair of kings currently threatening one another is 48.

Supply the Python code and your answer in a list of the queen positions, as in the above example.

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!