Member-only story
Intro — Python Algorithms: Eight Queens Problem
Problem Statement
The Eight Queens Problem is a classic example of a combinatorial puzzle in computer science. It involves the challenge of placing eight queens on an 8x8 chessboard in such a way that no two queens can attack each other. To understand the problem fully, let’s first explore how a queen moves in chess.
How The Queen Moves in Chess
The queen can move any number of unoccupied squares in a straight line — vertically, horizontally, or diagonally — combining the movement capabilities of both the rook and bishop. The diagram below shows all the possible moves (indicated by orange dots) that a queen can make on a chessboard.
At its optimal position, such as the center of the board depicted in Figure 1, a queen can control up to 27 squares. Here’s the breakdown:
- Vertical: 7 squares (excluding the square it occupies)
- Horizontal: 7 squares (excluding the square it occupies)
- Diagonals: 13 squares (excluding the square it occupies)










