Its a discrete probability question.
Imagine a boat and two banks on an integer line. One of the banks is at the origin and the other bank can be at any integer in range $[B+1,2B]$
If the right bank is at distance $d$ from the origin, then the boat can be at any integer point in the river in the range $[1,d-1]$. The boat always goes towards the nearest bank.
What is the expected distance travelled by the boat?
The right bank can be any of the possible distances with equal probability and the boat can be at any of the possible feasible distances with equal probability.
Suppose the distance between two banks is $2D$, then the expected distance travelled by the boat is $(1+2\ldots +D)/D=(D+1)/2$
Let $X$ be the boat's initial location, then $X$ is uniformly distributed over $\{1,2,\ldots,d-1\}$. The distance the boat travels is $$ Y := \min\{X, d-X\}. $$ Now, $X<d-X$ iff $X<d/2$, and since $X$ and $d$ are integer, this is equivalent to $X\leqslant \lfloor d/2\rfloor$. It follows that \begin{align} \mathbb E[Y] &= \sum_{j=1}^{d-1} (j\wedge d-j)\mathbb P(X=j)\\ &= \frac1{d-1}\left(\sum_{j=1}^{\lfloor d/2\rfloor} j + \sum_{j=\lfloor d/2\rfloor+1}^{d-1} (d-j) \right)\\ &= \frac d2 -\left\lfloor\frac d2\right\rfloor \left(1 - \frac{\left\lfloor\frac d2\right\rfloor}{d-1} \right) . \end{align}