Did you know there is a general formula for these 'hallway' problems?.
But, we can derive yours and show the formula works.
Using theta is a hint, not a requirement?.
When this problem gets interesting is when the width or diameter of the object is taken into account. This one is negligible though.
The length of the ladder is given by L=x+y
By similar triangles:
set to 0 and solve for x.
You will find the answer will be the same if you plug in a=4 and b=8 into the formula I gave at the beginning.