Eight Queens
A queen attacks along its row, its column, and both diagonals. Can you place eight of them on a chessboard so that none attacks another? There are 92 ways, or 12 if rotations and mirror images count as one. Place the queens yourself, or watch backtracking find them one step at a time. Click a square to place a queen, and click it again to take it away. No two queens may share a row, column, or diagonal. Solve shows the backtracking search one step at a time and keeps your queens. Next solution goes through every solution in order.
How it works
- Click a square to place a queen. The squares it attacks get a dot, so the safe ones stand out.
- Place all eight with no two in the same row, column, or diagonal. Queens that attack each other turn red.
- Press Solve to watch backtracking, or Next solution to see all 92, then save a PNG.
The rules
A queen moves any distance along a row, a column, or a diagonal. Eight queens on eight rows means exactly one queen in every row and every column, so the real puzzle is the diagonals. Size changes the board from 4×4 to 12×12, always with as many queens as rows.
Backtracking, step by step
Solve fills the board one row at a time. In each row it puts a queen on the first safe square. When a row has no safe square left, it takes back the queen in the row above and moves it on. The blue band shows the row it is working on, and Steps counts every queen placed or taken back. On an empty 8×8 board the first solution takes 218 steps.
92 solutions in 12 families
Turn a solution a quarter turn or reflect it in a mirror and you get another solution, so the 92 solutions fall into families. There are 12 families: eleven with 8 members and one with only 4, a solution that looks the same after a half turn.
Frequently asked questions
How many solutions does the eight queens puzzle have?
92. If solutions that are rotations or reflections of each other count as one, there are 12.
Is there a solution for every board size?
Every board from 4×4 up has one; 2×2 and 3×3 have none. The 6×6 board is unusual: it has only 4 solutions, fewer than the 10 of the 5×5 board.
What do Steps count?
Every queen the search places and every queen it takes back. Your own queens stay where they are, and the search works around them.
Why does Solve say no solution keeps my queens?
Some placements cannot be completed even though no two queens attack each other yet. The search has tried every way to fill the remaining rows. Remove a queen and try again.
Does this upload anything?
No. The board is drawn on a canvas in your browser. Save downloads a PNG. Edit opens that image in the PictorX editor.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Go to Editor