Check if two people starting from different points ever meet | PHP 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
< ? php function everMeet ( $ x1 , $ x2 , $ v1 , $ v2 ) { if ( $ x1 < $ x2 && $ v1 <= $ v2 ) return false ; if ( $ x1 > $ x2 && $ v1 >= $ v2 ) return false ; if ( $ x1 < $ x2 ) { list ( $ x1 , $ x2 ) = array ( $ x2 , $ x1 ) ; list ( $ v1 , $ v2 ) = array ( $ v2 , $ v1 ) ; } while ( $ x1 >= $ x2 ) { if ( $ x1 == $ x2 ) return true ; $ x1 = $ x1 + $ v1 ; $ x2 = $ x2 + $ v2 ; } return false ; } $ x1 = 5 ; $ v1 = 8 ; $ x2 = 4 ; $ v2 = 7 ; if ( everMeet ( $ x1 , $ x2 , $ v1 , $ v2 ) ) echo " Yes " ; else echo " No " ; ? >