Let
x = speed of the messenger
y = speed of the battalion
Recall that distance / speed = time
$\dfrac{20}{y}$ = time for the battalion to advance 20 miles
$\dfrac{20}{x - y}$ = time for messenger to go from rear to front
$\dfrac{20}{x + y}$ = time for messenger to go from front to rear
$\dfrac{20}{y} = \dfrac{20}{x - y} + \dfrac{20}{x + y}$
$(x - y)(x + y) = y(x + y) + y(x - y)$
$x^2 - y^2 = (xy + y^2) + (xy - y^2)$
$x^2 - 2xy - y^2 = 0$
$\dfrac{x^2}{y^2} - 2\dfrac{x}{y} - 1 = 0$
Let z = x/y
$z^2 - 2z - 1 = 0$
$z = \dfrac{-(-2) \pm \sqrt{(-2)^2 - 4(1)(-1)}}{2(1)}$
$z = \dfrac{2 \pm \sqrt{8}}{2} = \dfrac{2 \pm 2\sqrt{2}}{2}$
$z = 1 + \sqrt{2} ~ \text{ and } ~ 1 - \sqrt{2}$
Use z = 1 + sqrt(2)
$\dfrac{x}{y} = 1 + \sqrt{2}$
Time of Messenger = Time of Battalion
$\dfrac{d}{x} = \dfrac{20}{y}$
$d = 20\left( \dfrac{x}{y} \right)$
$d = 20\left( 1 + \sqrt{2} \right)$
$d = 48.28 ~ \text{miles}$ ← answer