-- nqueens.hs — n-queens backtracking solver.
--
-- `queens n` returns all solutions as lists of column positions,
-- one per row. Each call to `go k` extends all partial `(k-1)`-row
-- solutions by one safe queen, using a list comprehension whose guard
-- checks the new queen against all already-placed queens.

queens n = go n
  where
    go 0 = [[]]
    go k = [q:qs | qs <- go (k - 1), q <- [1..n], safe q qs]

safe q qs = check q qs 1

check q [] _     = True
check q (c:cs) d = q /= c && abs (q - c) /= d && check q cs (d + 1)

result = length (queens 8)
