

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


 
⍝Solution
accm←{⍺,((⍴⍵)=⍴⊃⍺)↑⊂⍵}               
atk←{∪∊(⊂⍵)+¯1 0 1×⊂⌽⍳⍴⍵}            
dfs←{⊃∇⍨/⌽(⊂⍺ ⍺⍺ ⍵),⍺ ⍵⍵ ⍵}          
qfmt←{⍵∘.=⍳⍴⍵}      
subs←{(⊂⍵),¨(⍳⍴⊃⍺)~atk ⍵}                 
queens←{qfmt¨(↓0 ⍵⍴0)accm dfs subs ⍬}
printqueens←{i←1⋄{⎕←'answer'i⋄⎕←⍵⋄i+←1}¨queens ⍵}
 
⍝Example
printqueens 6
 