The solution requires a little algebra. Let `x` be the distance in miles that the army marches during the horseman's run forward. Then the horseman traveled `40+x` miles while the army marched `x` miles. The return trip for the horseman is 40 miles shorter, since the army has traveled 40 miles by the time he finishes, so it is `x` miles for the horseman, while the army marches `40-x` miles. The total distances are then 40 miles for the army and `40+2x` miles for the horseman.

Since both the horseman and the army travel at constant rates, the ratio of their rates is also constant. So we have:

`(40+x)/x = (40+2x)/40`

or

`40(40+x)=(40+2x)x`

or

`1600+40x = 40x+2x^2`

or

`x^2 = 800`

So `x = sqrt 800 = 20 sqrt 2` and the horseman has traveled `40 + 40 sqrt 2` miles or about 96.6 miles.