TITLE: Optimal ladder position to maximize height reached
QUESTION [6 upvotes]: Suppose we have a ladder (with a unit length) and we want to position it to reach the highest point possible on a vertical wall. The terrain is sloped and can be described with a variable k. What is the optimal distance from the wall the ladder should be placed at, so the point reached is the highest? 
See the picture, we are looking for x.

I've concluded, "experimentally", that the ladder should be placed vertical to the terrain, but I've been unable to prove it. I didn't how to set a Lagrange correctly. (and yes, this was an exam question, I don't plan on scaling any walls!)

REPLY [7 votes]: Alternatively look at it like this. Take a point on the wall. What is the shortest ladder which reaches that point? Clearly one perpendicular to the ground (shortest line between ground and point). If the ladder is not perpendicular to the ground, we can reach the same point with a shorter ladder, which is perpendicular, and place our longer ladder higher up and parallel.