

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


to try :files :diag1 :diag2 :tried
  if :files = 0 [make "solutions :solutions+1  show :tried  stop]
  localmake "safe (bitand :files :diag1 :diag2)
  until [:safe = 0] [
    localmake "f bitnot bitand :safe minus :safe
    try bitand :files :f  ashift bitand :diag1 :f -1  (ashift bitand :diag2 :f 1)+1  fput bitnot :f :tried
    localmake "safe bitand :safe :safe-1
  ]
end
 
to queens :n
  make "solutions 0
  try (lshift 1 :n)-1 -1 -1 []
  output :solutions
end
 
print queens 8  ; 92