Harmonic Progression | Python3 program to check if a given array can form harmonic progression ; Find reciprocal of arr [ ] ; After finding reciprocal , check if the reciprocal is in A . P . To check for A . P . , first Sort the reciprocal array , then check difference between consecutive elements ; Driver code ; series to check whether it is in H . P ; Checking a series is in H . P or not
def checkIsHP ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE if ( n == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT rec = [ ] NEW_LINE for i in range ( 0 , len ( arr ) ) : NEW_LINE INDENT a = 1 / arr [ i ] NEW_LINE rec . append ( a ) NEW_LINE DEDENT return ( rec ) NEW_LINE rec . sort ( ) NEW_LINE d = rec [ 1 ] - rec [ 0 ] NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( rec [ i ] - rec [ i - 1 ] != d ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 / 5 , 1 / 10 , 1 / 15 , 1 / 20 , 1 / 25 ] NEW_LINE if ( checkIsHP ( arr ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT