I assume you have a drawing of this problem. If not, then draw it this way.
Draw a vertical segment on the left side of the paper. Starting at the lower endpoint, draw a horizontal segment to the right. You now have the wall and the floor. Now draw a slant segment connecting the two segments. This is the ladder. Mark the lower right acute angle alpha. Now using the same length segment, draw a new segment connecting the perpendicular ones a little lower on the wall than the previous one. It will end up on the floor to the right of the previous one. Label the distance between the segments on the wall q and the distance between the endpoints of the slant segments on the floor p. Now label the distance from the lower endpoint on the wall to the floor r, and the distance from the left endpoint on the wall to the wall s. The length of both slant segments is t.
We need to use sines and cosines to find expressions for p and q.
We'll start with sine and q.
Now we subtract the expression for r from the expression for q + r.
We have an expression for q in terms of the length of the ladder, t, and the angles alpha and beta.
Now we work on p by using the cosine of the angles.
Now we subtract the expression for s from the expression for p + s.
Now we have an expression for p in terms of t and the angles alpha and beta.
To find the ratio of p to q, we divide their expressions.
Cancel out t to get: