function number_of_attacks = find_attacks(A) [a b]=find(A); number_of_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)) number_of_attacks=number_of_attacks+1; end end end end