## Eight Queens Puzzle

The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard such that none of them is able to capture any other using the standard chess queen's moves.

The queens must be placed in such a way that no two queens would be able to attack each other.

Consequently, a solution requires that no two queens share the same row, column, or diagonal. The eight queens puzzle is an example of the more general

*n*queens puzzle of placing

*n*queens on an

*n*×

*n*chessboard for

*n*≥ 4.

Solutions to the Eight Queens Puzzle:

The eight queens puzzle has 92 distinct solutions. Solutions differing only by symmetry operations (i.e., rotations and reflections) of the board are counted as one solution. The puzzle has 12 unique solutions, four of which are presented below:

The eight queens puzzle has 92 distinct solutions. Solutions differing only by symmetry operations (i.e., rotations and reflections) of the board are counted as one solution. The puzzle has 12 unique solutions, four of which are presented below:

## Constructing a General Solution for n Queens Puzzle:

- Divide
*n*by 12. Remember the remainder (*n*is 8 for the eight queens puzzle). - Write a list of the even numbers from 2 to
*n*in order. - If the remainder is 3 or 9, move 2 to the end of the list.
- Append the odd numbers from 1 to
*n*in order, but, if the remainder is 8, switch pairs (i.e. 3, 1, 7, 5, 11, 9, …). - If the remainder is 2, switch the places of 1 and 3, then move 5 to the end of the list.
- If the remainder is 3 or 9, move 1 and 3 to the end of the list.
- Place the first-column queen in the row with the first number in the list, place the second-column queen in the row with the second number in the list, etc.

For *n* = 8 this results in the solution shown above. A few more
examples follow.

- 14 queens (remainder 2): 2, 4, 6, 8, 10, 12, 14, 3, 1, 7, 9, 11, 13, 5.

- 15 queens (remainder 3): 4, 6, 8, 10, 12, 14, 2, 5, 7, 9, 11, 13, 15, 1, 3.

- 20 queens (remainder 8): 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 3, 1, 7, 5, 11, 9, 15, 13, 19, 17.