function number_off_attacks = find_attacks(A) % This function finds the number of attacks between 8 queens % vectors a and b contain the positions of the queens [a b]=find(A); number_off_attacks = 0; for i=1:7 p1=a(i); q1=b(i); for j=i+1:8 p2=a(j); q2=b(j); if ((p1==p2) || (q1==q2) || (abs(p1-p2)==abs(q1-q2))) % || (abs(p1-p2)==abs(q2-q1))) number_off_attacks=number_off_attacks+1; end end end end