

Solve the eight queens puzzle.



You can extend the problem to solve the puzzle with a board of size   NxN.

For the number of solutions for small values of   N,   see   OEIS: A000170.



Related tasks

 A* search algorithm
 Solve a Hidato puzzle
 Solve a Holy Knight's tour
 Knight's tour
 Peaceful chess queen armies
 Solve a Hopido puzzle
 Solve a Numbrix puzzle
 Solve the no connection puzzle


procedure main()
    write(q(1), " ", q(2), " ", q(3), " ", q(4), " ", q(5), " ", q(6), " ", q(7), " ", q(8))
end
 
procedure q(c)
    static udiag, ddiag, row
 
    initial {
        udiag := list(15, 0)
        ddiag := list(15, 0)
        row := list(8, 0)
    }
 
    every 0 = row[r := 1 to 8] = ddiag[r + c - 1] = udiag[8 + r - c] do   # test if free
        suspend row[r] <- ddiag[r + c - 1] <- udiag[8 + r - c] <- r       # place and yield
end