Find number formed by K times alternatively reducing X and adding Y to 0 | Function to find the value obtained after alternatively reducing X and adding Y to 0 total K number of times ; Stores the final result after adding only Y to 0 ; Stores the final number after reducing only X from 0 ; Return the result obtained ; Driver Code
function positionAfterKJumps ( X , Y , K ) { let addY = Y * Math . floor ( K / 2 ) ; let reduceX = - 1 * X * ( Math . floor ( K / 2 ) + K % 2 ) ; return addY + reduceX ; } let X = 2 , Y = 5 , K = 3 ; document . write ( positionAfterKJumps ( X , Y , K ) ) ;