Check if a right | Storing all the possible changes to make the triangle right - angled ; Function to check if the triangle is right - angled or not ; Function to check if the triangle can be transformed to right - angled ; Boolean variable to return true or false ; If it is already right - angled ; Applying the changes on the co - ordinates ; Applying on the first co - ordinate ; Applying on the second co - ordinate ; Applying on the third co - ordinate ; If can 't be transformed ; Driver Code
let dx = [ - 1 , 0 , 1 , 0 ] ; let dy = [ 0 , 1 , 0 , - 1 ] ; function ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) { let a = ( ( x1 - x2 ) * ( x1 - x2 ) ) + ( ( y1 - y2 ) * ( y1 - y2 ) ) ; let b = ( ( x1 - x3 ) * ( x1 - x3 ) ) + ( ( y1 - y3 ) * ( y1 - y3 ) ) ; let c = ( ( x2 - x3 ) * ( x2 - x3 ) ) + ( ( y2 - y3 ) * ( y2 - y3 ) ) ; if ( ( a == ( b + c ) && a != 0 && b != 0 && c != 0 ) || ( b == ( a + c ) && a != 0 && b != 0 && c != 0 ) || ( c == ( a + b ) && a != 0 && b != 0 && c != 0 ) ) { return 1 ; } return 0 ; } function isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 ) { let x , y ; let possible = 0 ; if ( ifRight ( x1 , y1 , x2 , y2 , x3 , y3 ) ) { document . write ( " " ) ; return ; } else { for ( let i = 0 ; i < 4 ; i ++ ) { x = dx [ i ] + x1 ; y = dy [ i ] + y1 ; if ( ifRight ( x , y , x2 , y2 , x3 , y3 ) ) { document . write ( " " ) ; return ; } x = dx [ i ] + x2 ; y = dy [ i ] + y2 ; if ( ifRight ( x1 , y1 , x , y , x3 , y3 ) ) { document . write ( " " ) ; return ; } x = dx [ i ] + x3 ; y = dy [ i ] + y3 ; if ( ifRight ( x1 , y1 , x2 , y2 , x , y ) ) { document . write ( " " ) ; return ; } } } if ( ! possible ) document . write ( " " ) ; } let x1 = - 49 , y1 = 0 ; let x2 = 0 , y2 = 50 ; let x3 = 0 , y3 = - 50 ; isValidCombination ( x1 , y1 , x2 , y2 , x3 , y3 ) ;