The classic eight queens puzzle on boards from 4×4 to 10×10. Place one queen per row, column and diagonal and collect every solution.
What is the Eight Queens Puzzle?
The Eight Queens Puzzle asks you to place eight chess queens on an 8 by 8 chessboard so that no queen can attack another, which means no two queens share a row, a column or a diagonal. The same puzzle works on any square board: on an N by N board you place N queens.
It is a classic of both chess problems and mathematics. There are 92 ways to solve the 8 by 8 board, and finding even one by hand takes some method. Our version lets you play on boards from 4 by 4 to 10 by 10 and keeps count of every different solution you find.
How to play the Eight Queens Puzzle
Choose a board: pick a size from 4 by 4 to 10 by 10. The number of queens you need equals the size of the board, so 4 queens on 4 by 4 and 10 queens on 10 by 10. The board will not take more queens than that.
Place and remove: tap an empty square to put a queen there, and tap a queen to take it off. A queen attacks every square along its row, its column and both of its diagonals, as far as the edge of the board.
Conflicts: any queen that is attacked by another turns red, so you can see at once which queens are in conflict. Turn on Attack paths to shade every square the queens on the board attack; the squares left unshaded are the only safe ones.
Solving: the puzzle is solved when all N queens are on the board and none of them is red. The game then tells you whether this solution is new or one you found before, and how many of the solutions for this size you have found so far. Clear empties the board and resets the timer.
How to solve the eight queens problem
One per row, one per column. With N queens on an N by N board and no two in the same row or column, every row and every column holds exactly one queen. So work row by row: your only choice in each row is which column to use. After that, the only thing left to check is the diagonals.
Backtrack. Put a queen in the first safe square of the top row, then the first safe square of the next row, and so on. When a row has no safe square left, go back one row and move that queen to its next safe square. This is slow but always ends in a solution, and with Attack paths turned on, you can see the safe squares at a glance.
Use a staircase. A simple pattern solves many sizes: go row by row and put each queen two columns to the right of the one above, jumping back to the left side when you run out of columns. Listing the column of each queen, row by row: on 5 by 5, 1, 3, 5, 2, 4. On 7 by 7, 1, 3, 5, 7, 2, 4, 6. On 6 by 6 and 10 by 10, start in column 2: 2, 4, 6, 1, 3, 5 and 2, 4, 6, 8, 10, 1, 3, 5, 7, 9.
Fix the hard sizes. The simple pattern fails on 8 by 8 and 9 by 9, but a small change saves it. On 8 by 8: 2, 4, 6, 8, 3, 1, 7, 5. On 9 by 9: 4, 6, 8, 2, 5, 7, 9, 1, 3. On 4 by 4, one of the two solutions is 2, 4, 1, 3.
Turn and flip. Each solution gives others for free: rotate the board a quarter turn, a half turn or three quarters, or mirror it, and you get another valid arrangement. The game counts these as different solutions, so one answer can lead you to as many as eight. On 8 by 8, the 92 solutions come from 12 basic shapes: eleven of them give eight solutions each and one symmetric shape gives only four.
Collect them all. To find every solution on a board, go back to backtracking and keep going after each success, moving the last queen on to its next safe square each time.
Board sizes and how many solutions each has
Our Eight Queens Puzzle offers seven boards. The number of different solutions on each is: 4 by 4, 2; 5 by 5, 10; 6 by 6, 4; 7 by 7, 40; 8 by 8, 92; 9 by 9, 352; 10 by 10, 724. The 6 by 6 board is the odd one out, with fewer solutions than 5 by 5, which makes it a good small challenge. Boards of 2 by 2 and 3 by 3 have no solution at all, which is why the game starts at 4.
Other versions of the puzzle exist, for example using other chess pieces, such as placing the most knights or rooks that do not attack each other, or asking for the fewest queens that together attack every square.
History of the eight queens puzzle
The puzzle was published in 1848 by the chess composer Max Bezzel. In 1850 Franz Nauck published solutions and extended the question to boards of any size, which is the N queens problem played here. Mathematicians, including Carl Friedrich Gauss, took an interest in it.
In computer science, the puzzle is a standard example of backtracking search. Edsger Dijkstra used it in 1972 to show how to design such a search step by step, and it is still a common exercise in programming courses.
Play the Eight Queens Puzzle on Hevagames
Our Eight Queens Puzzle runs in the browser on phones, tablets and computers, with nothing to download. Tap a square to place or remove a queen. On a keyboard, the arrow keys move between squares, and Enter or Space places or removes a queen on the focused square.
There is no time limit. A timer starts with your first queen so you can try to beat your best time for each size. After a solution you can keep the board on screen to look at it, or start a new round. The board in progress, your best times and the list of solutions you have found on each size are saved in your browser.
How to play
- 1Pick a board size from 4×4 to 10×10. On an N×N board you place N queens.
- 2Tap an empty square to place a queen, tap a queen to remove it.
- 3Queens that attack each other turn red. A queen attacks along its row, column and both diagonals.
- 4The puzzle is solved when all N queens are on the board and none is red.
Controls
Tips
- Go row by row: each row and each column must hold exactly one queen.
- Turn on attack paths to see which squares are still free.
- 6×6 has only 4 solutions, 8×8 has 92 and 10×10 has 724. The game counts the different ones you find.
