Check if two people starting from different points ever meet | Python3 program to find if two people starting from different positions ever meet or not . ; If speed of a person at a position before other person is smaller , then return false . ; Making sure that x1 is greater ; Until one person crosses other ; first person taking one jump in each iteration ; second person taking one jump in each iteration ; Driver code
def everMeet ( x1 , x2 , v1 , v2 ) : NEW_LINE INDENT if ( x1 < x2 and v1 <= v2 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT if ( x1 > x2 and v1 >= v2 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT if ( x1 < x2 ) : NEW_LINE INDENT x1 , x2 = x2 , x1 ; NEW_LINE v1 , v2 = v2 , v1 ; NEW_LINE DEDENT while ( x1 >= x2 ) : NEW_LINE INDENT if ( x1 == x2 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT x1 = x1 + v1 ; NEW_LINE x2 = x2 + v2 ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT x1 = 5 ; NEW_LINE v1 = 8 ; NEW_LINE x2 = 4 ; NEW_LINE v2 = 7 ; NEW_LINE if ( everMeet ( x1 , x2 , v1 , v2 ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT