The eight queens puzzle has 92 distinct solutions. If solutions that differ only by the symmetry operations of rotation and reflection of the board are counted as one, the puzzle has 12 solutions.
My code gives 24 unique solutions, how can I fix it, or is there any better method?
Length[sols=Cases[Permutations[Range[8]],{a_,b_,c_,d_,e_,f_,g_,h_}/;
a+1!=b+2!=c+3!=d+4!=e+5!=f+6!=g+7!=h+8 && a-1!=b-2!=c-3!=d-4!=e-5!=f-6!=g-7!=h-8]]
Length[DeleteDuplicates[sols, #+#2==Table[9,8]||#==Reverse[#2]||Reverse[#]+#2==Table[9,8]&]]
Comments
Post a Comment