Total number of triplets ( A , B , C ) in which the points B and C are Equidistant to A | C # implementation to find the total number of Triplets in which the points are Equidistant ; 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
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int numTrip ( ArrayList points ) { int res = 0 ; for ( int i = 0 ; i < points . Count ; ++ i ) { Dictionary < long , int > map = new Dictionary < long , int > ( ) ; for ( int j = 0 ; j < points . Count ; ++ j ) { if ( j == i ) continue ; int dy = ( ( pair ) points [ i ] ) . second - ( ( pair ) points [ j ] ) . second ; int dx = ( ( pair ) points [ i ] ) . first - ( ( pair ) points [ j ] ) . first ; int key = dy * dy ; key += dx * dx ; if ( map . ContainsKey ( key ) ) { map [ key ] ++ ; } else { map [ key ] = 1 ; } } foreach ( int p in map . Values ) res += p * ( p - 1 ) ; } return res ; } public static void Main ( string [ ] args ) { ArrayList mat = new ArrayList ( ) { new pair ( 0 , 0 ) , new pair ( 1 , 0 ) , new pair ( 2 , 0 ) } ; Console . Write ( numTrip ( mat ) ) ; } }