EX_03/level-2/n_queens
2025-10-05 17:10:55 +01:00
..
Makefile added level-1 2025-09-23 08:41:21 +01:00
n_queens_clean.c Added cleaner resolution for level-2 n_queens 2025-09-29 22:28:33 +01:00
n_queens.c Replaced subject resolutions of level-2 with backtracking 2025-09-25 08:16:02 +01:00
README.md Edited README's, added broken_gnl exercise, LICENSE and main README 2025-10-05 17:10:55 +01:00
subject.txt added level-1 2025-09-23 08:41:21 +01:00

N-Queens

What is the N-Queens Problem?

Imagine you have a chessboard and some queens (the most powerful pieces in chess). The N-Queens problem is like a puzzle where you need to place N queens on an N×N chessboard so that none of them can attack each other.

What's a Queen in Chess?

A queen is the strongest piece in chess. She can move:

  • Horizontally (left and right)
  • Vertically (up and down)
  • Diagonally (in any diagonal direction)

She can move as many squares as she wants in these directions!

The Challenge

Let's say we want to solve the 4-Queens problem (N=4):

  • We have a 4×4 chessboard (16 squares total)
  • We need to place 4 queens
  • NO queen can attack any other queen

Example: What Does "Attack" Mean?

If we put a queen at position (0,0) - that's the top-left corner - she can attack:

Q . . .  ← Queen here attacks all positions marked with X
X . . .
X . . .
X . . .
Q X X X  ← Queen attacks horizontally
. . . .
. . . .
. . . .
Q . . .  ← Queen attacks diagonally
. X . .
. . X .
. . . X

So we can't put any other queen in any of those X positions!