Solution (source code)

= Solution

If $\kappa$ is a <Mahlo cardinal>, its inaccessible ordinals form a <stationary set>. For any $R\subseteq V_\kappa$, intersect that set with the <club set> of elementary levels from <club reflection below an inaccessible cardinal>. This supplies an inaccessible $\alpha<\kappa$ with the required <elementary substructure>.

Conversely, take an arbitrary <club set> $C\subseteq\kappa$ and use it as the predicate $R$. In $\langle V_\kappa,\in,C\rangle$, the sentence asserting that predicate-marked ordinals occur above every ordinal is true. Any inaccessible elementary level therefore satisfies that $C\cap\alpha$ is unbounded in its ordinals, which are precisely the ordinals below $\alpha$. Since $C$ is closed and $\alpha$ is a limit ordinal, $\alpha\in C$. The assumed reflection property consequently gives an inaccessible ordinal in every <club set>. Hence the inaccessible ordinals are stationary and
$$
\boxed{\kappa\text{ is Mahlo}\iff
\text{every predicate has an inaccessible elementary rank level below }\kappa.}
$$