Solution (source code)

= Solution

The $[SU(3)]^2U(1)$ condition gives $u+d=2q$, which is even because all hypercharges are <integers>. The sum $u+d$ and difference $u-d$ have the same parity, so $u-d$ is even. Therefore
$$
\boxed{u-d=2y\quad\text{for some }y\in\mathbb Z}.
$$
Solving the sum and difference equations gives
$$
\boxed{u=q+y,\qquad d=q-y}.
$$