In one liner if current position of ball falls under L and R then absolute distance between C and R after swapping will be equal to absolute distance between L and C before swapping. i.e C-L = R-X => X = L+R-C, where X = current swapped position of ball.