text: Find the minimum difference between Shifted tables of two numbers | Utility function to find GCD of a and b ; Returns minimum difference between any two terms of shifted tables of ' a ' and ' b ' . ' x ' is shift in table of ' a ' and ' y ' is shift in table of ' b ' . ; Calculate gcd of a nd b ; Calculate difference between x and y ; Driver Code
code: < ? php function gcd ( $ a , $ b ) { while ( $ b != 0 ) { $ t = $ b ; $ b = $ a % $ b ; $ a = $ t ; } return $ a ; } function findMinDiff ( $ a , $ b , $ x , $ y ) { $ g = gcd ( $ a , $ b ) ; $ diff = abs ( $ x - $ y ) % $ g ; return min ( $ diff , $ g - $ diff ) ; } $ a = 20 ; $ b = 52 ; $ x = 5 ; $ y = 7 ; echo findMinDiff ( $ a , $ b , $ x , $ y ) , " STRNEWLINE " ; ? >