% This program solves the 6-queens problem using guess and check % The program is being executed until the first solution is found clear clc counter = 0; result = zeros(6); while 1 A = zeros(6); B = randperm(36,6); A(B) = 1; numAttacks = find_attacks_YES_NO(A); if (numAttacks == 0) result = A; break; endif counter = counter + 1; if (rem(counter,10000)==0) counter endif endwhile counter result