
We have $(a+x)^2+y^2=x^2+(b+y)^2$ (as they are both equal to the length of the ladder). And $\tan\alpha=\frac{b+y}{x}$ and $\tan\beta=\frac{y}{a+x}$. Eliminating $x,y$ between these three equation, we get
$$
a^2 \tan (\beta )+2 a b-b^2 \tan (\beta )=\tan (\alpha ) \left(-a^2+2 a b \tan (\beta )+b^2\right)\ .
$$
Dividing both sides by $ab$, we get
$$
(a/b) \tan (\beta )+2 -(b/a) \tan (\beta )=\tan (\alpha ) \left(-(a/b)+2 \tan (\beta )+(b/a)\right)\ .
$$
Setting $a/b=\xi$, this is equivalent to
$$
\xi \tan (\beta )+2 -(1/\xi) \tan (\beta )=\tan (\alpha ) \left(-\xi+2 \tan (\beta )+(1/\xi)\right)\ ,
$$
which can be solved for $\xi$.
EDIT: Solving for $\xi$, one obtains two solutions:$\xi=-\mathrm{cot}((\alpha+\beta)/2)$ (which is not acceptable because, for $0<\alpha+\beta<\pi$
it gives a negative value for the ratio $a/b$), and $\xi=\tan((\alpha+\beta)/2)$. Then, using a tangent of half-angle formula https://en.wikipedia.org/wiki/Tangent_half-angle_formula I can write this as
$$
\xi=\frac{a}{b}=\frac{\cos\beta-\cos\alpha}{\sin\alpha-\sin\beta}\ ,
$$
i.e. with a minus sign difference with respect to the solution posted by the OP, which seems in fact incorrect. Take for example the case $\alpha=\pi/4$ and $\beta=\pi/6$. Then we have $x=b+y=L/\sqrt{2}$, $y=L/2$ and $a+x=(L/2)\sqrt{3}$, if $L$ is the length of the ladder. Then, $a/b=-2-\sqrt{2}+\sqrt{3}+\sqrt{6}\approx 0.76... $, while $\frac{\cos (\alpha )-\cos (\beta )}{\sin (\alpha )-\sin (\beta )}=\left(1+\sqrt{2}\right) \left(\sqrt{2}-\sqrt{3}\right)\approx -0.76...$