% distribucija broja napada kraljica na tabli 6x6 % za sve moguce polozaje kraljica. Ukupan broj ispitanih kombinacija % je (36 nad 6) = 1947792. Resenja su sacuvana u promenljivoj "solutions" % Broj napada varira izmedu 0 i 15. Promenljiva numAttacks sadrzi % koliko puta se dogodio koji broj napada. numAttacks(1) je broj resenja, % numttacks(2) je broj pozicija sa jednim napadom, itd. % Funkcija find_attacks_universal pronalazi broj resenja za bilo koju velicinu table. % Promenljiva whereIsSolution sadrzi redni broj resenja. clear clc N = 6; A = zeros(N); numAttacks = zeros(1,sum(1:N-1)+1); solutions = zeros(N); whereIsSolution = []; counter = 0; for i1 = 1 : N^2-5 for i2 = i1+1 : N^2-4 for i3 = i2+1 : N^2-3 for i4 = i3+1 : N^2-2 for i5 = i4+1 : N^2-1 for i6 = i5+1 : N^2 temp = [i1 i2 i3 i4 i5 i6]; A(temp) = 1; x = find_attacks_universal(A); if x==0 A solutions(:,:,end+1) = A; whereIsSolution (end+1) = counter; endif numAttacks(x+1) = numAttacks(x+1)+1; A = zeros(N); counter = counter + 1; if rem(counter,10000)==0 counter bar(0:15, numAttacks), axis([-1 16 0 500000]), ... text(0:15, numAttacks+5000, num2str(numAttacks'), 'FontSize', 10, ... 'HorizontalAlignment','Center','VerticalAlignment','Bottom') xticks([0:15]) xticklabels({'0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15'}) xlabel(counter) drawnow endif endfor endfor endfor endfor endfor endfor bar(0:15, numAttacks), axis([-1 16 0 500000]), ... text(0:15, numAttacks+5000, num2str(numAttacks'), 'FontSize',10, ... 'HorizontalAlignment','Center','Verticalalignment','Bottom') xticks([0:15]) xticklabels({'0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15'}) xlabel(counter) solutions(:,:,1)=[];