Problem # 19 : Queens at peace

We've all played chess atleast we know how to. Anyway as you know the queen can move in a straight line across a row or down a column or diagonally ie all moves except that of a knight.

Suppose there is a chess board of size NxN it is possible to place N queens on it in such a manner that none of the queens can "kill" any other queen.

Write a sub-routine QUEENS(N) which displays a chess board of size N and places N queens on it so none of them can kill each other. Please note it is impossible to have such a situation on a chess board with less than 16 squares (less than a 4x4 board).

Sample Output
On a 8x8 chess board 8 queens should be placed as follows :-

[Sample Output]

Similarly QUEENS(4) should return

[Sample Output]

And QUEENS(13) should return

[Sample Output]
 
Note that N queens can be placed on the chess board in more than one way so that they cannot kill each other.
For example simply rotating the solutions on this site by 90 degress will give another solution.
So even if you do not get the exactly the same solutions it may be right.
Previous Problem
Return to problems at The Vault
(Back to problems at The Vault )
Next Problem

LinkExchange
LinkExchange Member
1