Twin Pythagorean triplets in an array | Function to check if there exist a twin pythagorean triplet in the given array ; Loop to check if there is a Pythagorean triplet in the array ; Check if there is consecutive triple ; Calculate square of array elements ; Driver Code ; Given array arr [ ] ; Function call
def isTriplet ( ar , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT for k in range ( j + 1 , n ) : NEW_LINE INDENT if ( abs ( ar [ i ] - ar [ j ] ) == 1 or abs ( ar [ j ] - ar [ k ] ) == 1 or abs ( ar [ i ] - ar [ k ] ) == 1 ) : NEW_LINE INDENT x = ar [ i ] * ar [ i ] NEW_LINE y = ar [ j ] * ar [ j ] NEW_LINE z = ar [ k ] * ar [ k ] NEW_LINE if ( x == y + z or y == x + z or z == x + y ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 1 , 4 , 6 , 5 ] NEW_LINE ar_size = len ( arr ) NEW_LINE if isTriplet ( arr , ar_size ) : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT DEDENT