Time taken by two persons to meet on a circular track | PHP implementation of above approach ; Function to return the time when both the persons will meet at the starting point ; Time to cover 1 round by both ; Finding LCM to get the meeting point ; Function to return the time when both the persons will meet for the first time ; Driver Code ; Calling function
< ? php function gcd ( $ a , $ b ) { return $ b ? gcd ( $ b , $ a % $ b ) : $ a ; } function startingPoint ( $ Length , $ Speed1 , $ Speed2 ) { $ result1 = 0 ; $ result2 = 0 ; $ time1 = $ Length / $ Speed1 ; $ time2 = $ Length / $ Speed2 ; $ result1 = gcd ( $ time1 , $ time2 ) ; $ result2 = $ time1 * $ time2 / ( $ result1 ) ; return $ result2 ; } function firstTime ( $ Length , $ Speed1 , $ Speed2 ) { $ result = 0 ; $ relativeSpeed = abs ( $ Speed1 - $ Speed2 ) ; $ result = ( ( float ) $ Length / $ relativeSpeed ) ; return $ result ; } $ L = 30 ; $ S1 = 5 ; $ S2 = 2 ; $ first_Time = firstTime ( $ L , $ S1 , $ S2 ) ; $ starting_Point = startingPoint ( $ L , $ S1 , $ S2 ) ; echo " Met ▁ first ▁ time ▁ after ▁ " . $ first_Time . " ▁ hrs " . " STRNEWLINE " ; echo " Met ▁ at ▁ starting ▁ point ▁ after ▁ " . $ starting_Point . " ▁ hrs " . " STRNEWLINE " ; ? >