function number_of_attacks = find_attacks_gen(A, N) [a b]=find(A); number_of_attacks=0; for i=1:N-1 p1=a(i); q1=b(i); for j=i+1:N 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