Call the length of the row 1. Below is a diagram.
The top row is the starting position. The messenger starts at the left and the captain is to the far right.
The middle row shows the messenger reaching the captain.
The third row shows the ending position.
The bottom two rows indicate distances. x is how far past the captain's original position the messenger walks.
Code:M------------------C
-------------------MC
M------------------C
| | |
\--------1---------/ \----x-----/ \1-x/
On the way to the captain, the messenger walks 1+x in the same time that the row moves x.
On the way back, the messenger walks x in the same time that the row moves 1-x.
Therefore, (1+x)/x = x/(1-x)
1-x^2 = x^2
1 = 2*x^2
x = sqrt(1/2) = sqrt(2)/2
The messenger walks 1+x+x = 1 + sqrt(2)/2 + sqrt(2)/2 = 1 + sqrt(2).