Are you wanting a maximum angle or shortest ladder length? I'll assume the latter:
Let t = the distance from the base of the building to the foot of the ladder.
Let h = the vertical distance of the ladder above the ground.
Let x = the angle the ladder makes with the ground in radians (as differentiation becomes a lot simpler when working with radians).
The distance, a, of the ladder is given by:
\(\displaystyle a = sqrt{t^2 + h^2}\)
By basic trigonometry, \(\displaystyle tan(x) = \frac{h}{t}\\)
Also, by similar triangles, \(\displaystyle \frac{8}{t-27}\ = \frac{h}{t}\\)
Hence, \(\displaystyle tan(x) = \frac{8}{t-27}\\), \(\displaystyle t = 8cotx + 27\)
Similarly: \(\displaystyle h = 8 + 27tanx\)
So substituting these in, we obtain:
\(\displaystyle a = sqrt{64cot^2x + 432cotx + 793 + 432tanx + 729*tan^2x}\)
Now find da/dt, set it equal to 0, and solve for the angle x (the solution should be in radians and the angle should be acute).