Total number of triplets ( A , B , C ) in which the points B and C are Equidistant to A | Function to count such triplets ; Iterate over all the points ; Iterate over all points other than the current point ; Compute squared euclidean distance for the current point ; Compute nP2 that is n * ( n - 1 ) ; Return the final result ; Driver code
def numTrip ( points ) : NEW_LINE INDENT res = 0 NEW_LINE for i in range ( len ( points ) ) : NEW_LINE INDENT map = { } NEW_LINE for j in range ( len ( points ) ) : NEW_LINE INDENT if ( j == i ) : NEW_LINE INDENT continue NEW_LINE DEDENT dy = points [ i ] [ 1 ] - points [ j ] [ 1 ] NEW_LINE dx = points [ i ] [ 0 ] - points [ j ] [ 0 ] NEW_LINE key = dy * dy NEW_LINE key += dx * dx NEW_LINE map [ key ] = map . get ( key , 0 ) + 1 NEW_LINE DEDENT for p in map : NEW_LINE INDENT res += map [ p ] * ( map [ p ] - 1 ) NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT mat = [ [ 0 , 0 ] , [ 1 , 0 ] , [ 2 , 0 ] ] NEW_LINE print ( numTrip ( mat ) ) NEW_LINE DEDENT