# Placing n Queens on n x n board

This problem is known as n queens puzzle: How can we distribute n queens on a chess grid of n $\times$ n so that no queen can threaten another.

Many solutions are possible for n > 4. To answer this question, show a single solution for n from 4 to 10 as well as an algorithm for where to place the queens.

• Here is a solution when n = 8 • You can simply specify that solutions are to be simple algorithms and not require brute force approaches (i.e. be possible to implement with pen paper) – March Ho Feb 15 '15 at 10:26
• it goes without saying :) – Abr001am Feb 15 '15 at 10:31
• I do think you should clarify whether you mean how many ways it can be done, or if you want an algorithm that can provide just one solution in each case. – HKOB Feb 15 '15 at 13:45
• I made the post look nicer, I hope you don't mind :D – warspyking Feb 16 '15 at 0:55
• This is a well known problem for $8 \times 8$, which has 12 different solutions if rotations and reflections are considered identical. The one you post has a nice pattern, but not all do. It is not clear what the question is. – Ross Millikan Feb 18 '15 at 3:43

## 1 Answer

Single solutions are shown below for values of n from 4 to 10. Placement of the queens is based on the algorithm described in the Wikipedia page for the eight queens puzzle which is:

"Let (i, j) be the square in column i and row j on the n × n chessboard, k an integer.

1. If n is even and n ≠ 6k + 2, then place queens at (i, 2i) and (n/2 + i, 2i - 1) for i = 1,2,...,n/2.
2. If n is even and n ≠ 6k, then place queens at (i, 1 + (2i + n/2 - 3 (mod n))) and (n + 1 - i, n - (2i + n/2 - 3 (mod n))) for i = 1,2,...,n/2.
3. If n is odd, then use one of the patterns above for (n - 1) and add a queen at (n, n)."  • yes this s the most optimal solution with the least complexity O(1) . good job . – Abr001am Feb 19 '15 at 17:58