Pythagorean right triangle
a^2 + b^2 = c^2
Let the length of the ladder be x.
One side is x - 16.
The other side is x - 8.
(x-16)^2 + (x-8)^2 = x^2
x^2 - 32x + 256 + x^2- 16 x+64 = x^2
x^2 - 48 x + 320 = 0
( x- 40 ) (x-8) = 0
x = 40 or x= 8
we discard the second so x = 40