Solution (source code)

= Solution

<Shannon second coding theorem> states that the operational capacity of a discrete memoryless channel equals
$$
C=\max_{P_X}I(X;Y):
$$
every rate below $C$ is achievable with error probability tending to zero, while rates above $C$ are not.

Put $d=b-a$. If $d=0$, then $Y=X+a$, so $X$ is recovered exactly and $C=1$ bit. If $|d|\geq2$, the two output supports
$$
\{a,b\},\qquad\{a+1,b+1\}
$$
are disjoint, so again $Y$ determines $X$ and $C=1$.

If $|d|=1$, one output value is common to both inputs and occurs with probability $1/2$ independently of the input, while either of the other two values reveals the input. The channel is therefore a binary erasure channel with erasure probability $1/2$, whose capacity is $1/2$ bit. Hence
$$
\boxed{
C=\begin{cases}
1/2,&|b-a|=1,\\
1,&|b-a|\ne1.
\end{cases}}
$$