The classic problem
A queen moves any distance along a row, a column or a diagonal. Eight queens on an 8×8 board means one in every row and every column, so the diagonals are what make it hard. It's easy to place six queens safely and then find no square left for the seventh.
Where the puzzle comes from
Max Bezzel, a German chess composer, published the puzzle in the Berliner Schachzeitung in 1848. Franz Nauck published all 92 solutions in 1850 and asked the same question for a board of any size, which is now called the n queens problem. Carl Friedrich Gauss wrote about it in his letters that year too.
In 1972 Edsger Dijkstra used it to teach structured programming, and it is still a common exercise for computer science students.
Why there are 92 solutions
On an 8×8 board there are 92 ways to place the queens. Many of them are one pattern turned or flipped: rotate a solution a quarter turn, or look at it in a mirror, and you get another solution. Group those together and 12 distinct solutions are left. Eleven of them each make eight solutions. The twelfth looks the same after a half turn, so it only makes four.
Bigger boards have far more: 724 on 10×10 and 14,200 on 12×12. The table above lists every size from 4×4 to 12×12, and your browser can count them again to check.
Backtracking explained simply
Backtracking is trial and error with a memory. Put a queen in the first safe square of row 1, then in the first safe square of row 2, and keep going down. When a row has no safe square left, go back one row and move that queen to its next safe square. If it runs off the end of its row, go back one more row.
Because each row holds exactly one queen, the search never wastes time on boards with two queens in a row. On 8×8 it places 113 queens before it finds the first solution, and 2,056 to find all 92. A computer does that almost instantly, so the walkthrough above slows it down for you to follow.
The same idea solves sudoku, mazes and many other puzzles: make a choice, follow it, and undo it when it leads nowhere.
Queens and star battle
Star battle uses a close cousin of these rules. The board is split into regions, and in the one-star version each row, column and region needs one star. Stars may share a long diagonal but can't touch, not even at a corner. Play today's star battle, or the one-star grids as the queens puzzle.
Common questions
How do you solve the 8 queens puzzle?
Put one queen in each row, and choose each square so it shares no column or diagonal with the queens above it. When you get stuck, move the last queen along its row. One answer, row by row from the top, uses columns 1, 5, 8, 6, 3, 7, 2 and 4.
How many solutions does the eight queens puzzle have?
92. If you count rotations and reflections of the same pattern as one, there are 12.
Does the n queens puzzle work on other board sizes?
Yes. Every board from 4×4 up has at least one solution, while 2×2 and 3×3 have none. The board on this page goes from 4×4 to 12×12.
How many solutions does the 4 queens problem have?
Two, and each is the mirror image of the other. 5×5 has 10 and 6×6 has only 4, the one size above 3×3 where the count goes down.
Is the queens game the same as the eight queens puzzle?
No. The queens game is the one-star version of star battle: the board has coloured regions, and queens may share a long diagonal as long as they don't touch. The eight queens puzzle has no regions and rules out whole diagonals.