Calculus - Fence over a wall.

A fence 5 feet tall runs parallel to a tall building at a distance of 4 feet from the building. What is the length of the shortest ladder that will reach from the ground over the fence to the wall of the building?

A fence 5 feet tall runs parallel to a tall building at a distance of 4 feet from the building. What is the length of the shortest ladder that will reach from the ground over the fence to the wall of the building?

Use similar triangles.
The smaller triangle has a base of x and a height of 5
The larger triangle has a base of 4+x and and unknown height, y.
Using the ratio, x/5 = (4+x)/y, solve for y and replace that into the formula
x^2 +y^2 = z^2

Take the derivative of z(x) = square root (x squared + y squared)
and find the critical points. Test for a min value and plug x back into
xsquared plus ysquared = zsquared to solve for z (lenght of ladder)

Sorry. That is super confusing without a diagram, but hopefully it somewhat helped.