Number of steps required to reach point ( x , y ) from ( 0 , 0 ) using zig | Function to return the required position ; Driver Code
function countSteps ( x , y ) { if ( x < y ) { return x + y + 2 * parseInt ( ( y - x ) / 2 ) ; } else { return x + y + 2 * parseInt ( ( ( x - y ) + 1 ) / 2 ) ; } } var x = 4 , y = 3 ; document . write ( countSteps ( x , y ) ) ;