The 5×5 toroidal queens problem asks: in how many ways can 5 non-attacking queens be placed on a 5×5 chessboard whose edges wrap around (forming a torus)? Two queens attack each other if they share a row, column, or toroidal diagonal.
Why 5×5 is Special
The number 5 is the smallest integer greater than 1 for which a complete toroidal queens solution exists. The existence condition requires gcd(n, 6) = 1 — that n be coprime to both 2 and 3. The table below shows the first few values:
| n | gcd(n,6) | Complete solution? |
|---|---|---|
| 2 | 2 | No |
| 3 | 3 | No |
| 4 | 2 | No |
| 5 | 1 | Yes — 40 solutions |
| 6 | 6 | No |
| 7 | 1 | Yes — 168 solutions |
| 8 | 2 | No |
Because 5 is prime and coprime to 6, it is the first non-trivial board size where the puzzle has any solutions at all. This makes it the canonical example for studying toroidal queen placement.
Attack Rules on the 5×5 Torus
Two queens at (r₁, c₁) and (r₂, c₂) attack each other on a 5×5 torus if any of the following hold:
- Same row: r₁ ≡ r₂ (mod 5)
- Same column: c₁ ≡ c₂ (mod 5)
- Same main diagonal: (r₁ − c₁) ≡ (r₂ − c₂) (mod 5)
- Same anti-diagonal: (r₁ + c₁) ≡ (r₂ + c₂) (mod 5)
A valid placement uses exactly one queen per row and one per column (so it is a permutation of columns [0..4]) and additionally requires all five main-diagonal residues and all five anti-diagonal residues to be distinct. Because there are exactly 5 residues mod 5, each diagonal class must be used exactly once — a much more symmetric requirement than on a standard board.