Traverse through matrix and find pairs p1 and p2
for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if ( arr [ i ] [ j ] == '1' ) : NEW_LINE INDENT if ( p1 [ 0 ] == - 1 ) : NEW_LINE INDENT p1 = [ i , j ] NEW_LINE DEDENT else : NEW_LINE INDENT p2 = [ i , j ] NEW_LINE DEDENT DEDENT DEDENT DEDENT p3 = p1 NEW_LINE p4 = p2 NEW_LINE