This is the famous "ladder and box problem" (Google it for further information). Using similar triangles, you can get an equation for x in the form This is a fourth degree equation, so in theory it can be exactly solved, but there is no easy way to do so. In the particular case where the box is square ( ), there is a trick to split the quartic equation into two quadratic equations, but that can't be done in the general case.

You can check from the quartic equation that at most two of the solutions can be positive real numbers.

The problem was apparently first investigated by Newton in hisArithmetica universalis(1707).