Question: Write a program getPositions in Python that takes as input a list L representing a partial solution to the n-Queens problem and a positive integer

Write a program getPositions in Python that takes as input a list L representing a partial solution to the n-Queens problem and a positive integer n representing the dimension of the nn chessboard. The input list contains the positions of the Queens currently placed on the board (or is empty if no Queens have been placed). You should use the same list representation as you use in Task 3 of Workshop 6, that is, the entry L[i] gives the row position of the Queen in column i. You may assume that the partial solution gives the positions of the Queens in the first i columns and that the other columns are empty. Your program should return a list containing possible row positions for a Queen to be placed in the next column on the board. (The index of the next column can be obtained by the length of L.)

For example: If your list is [5,3] and n = 6, your program should return the list [0,1], that is, a Queen could be placed at row 0 column 2, or row 1 column 2, of the board.

Some further examples: If your list is empty and n = 5, your program should return the list [0,1,2,3,4]. If your list is [3,1] and n = 4, your program should return an empty list.

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!