Solution (source code)

= Solution

Take the proposal density $h(x)=e^{-x}\mathbf1_{x\geq0}$. For the target <half-normal distribution>,
$$
\frac{f(x)}{h(x)}
=\sqrt{\frac2\pi}\exp\left(-\frac{x^2}{2}+x\right)
=\sqrt{\frac{2e}{\pi}}\exp\left(-\frac{(x-1)^2}{2}\right).
$$
The ratio is maximized at $x=1$, so the sharp envelope constant is
$$
\boxed{M=\sqrt{\frac{2e}{\pi}}}.
$$
Generate $X=-\log U_1$ and an independent uniform $U_2$, and accept $X$ when
$$
U_2\leq\frac{f(X)}{Mh(X)}
=e^{-(X-1)^2/2}.
$$