Sand Timer Flip Counting Problem | Recursive function to return the gcd of a and b ; Everything divides 0 ; Function to print the number of flips for both the sand timers ; Driver code
function gcd ( a , b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } function flip ( a , b ) { let lcm = parseInt ( ( a * b ) / gcd ( a , b ) ) ; a = parseInt ( lcm / a ) ; b = parseInt ( lcm / b ) ; document . write ( ( a - 1 ) + " " + ( b - 1 ) ) ; } let a = 10 ; let b = 5 ; flip ( a , b ) ;