% solve the 6-queens problem systematically using brute force clear clc counter = 0; result = zeros(6); A = zeros(6); for q1 = 1 : 6 for q2 = 1 : 6 for q3 = 1 : 6 for q4 = 1 : 6 for q5 = 1 : 6 for q6 = 1 : 6 ## for q7 = 1 : 7 ## for q8 = 1 : 8 A(q1,1)=1; A(q2,2)=1; A(q3,3)=1; A(q4,4)=1; A(q5,5)=1; A(q6,6)=1; ## A(q7,7)=1; ## A(q8,8)=1; numAttacks = find_attacks_YES_NO(A); if (numAttacks == 0) result(:,:,end+1) = A; A endif counter = counter + 1; if (rem(counter,1000)==0) counter A endif A = zeros(6); ## endfor ## endfor endfor endfor endfor endfor endfor endfor result(:,:,1)=[]; result