There are two ways to calculate the length of the ladder. If the height where it touches the building is and the distance from the bottom of the ladder to the building is , then the length of the ladder can be calculated using two different formulas.

There's a bit of algebra involved, but, you end up with

So you want to minimize (minimizing will be easier and will give the same result) given that .

Doing this calculation doesn't seem to lead into anything nice though. ( ends up being the irrational solution to a cubic polynomial.) I got and so