Review of an old post in analysis concerning distance between a point and a set. I was looking around and found this old post :
Consider $C([0,1])$ with the $\sup$-norm. Let 
$$N = \bigg\{ f\in C([0,1]) | \int_0^1 f(x)dx = 0\bigg\}$$
be the closed linear subspace of $C([0,1])$ of functions with zero mean. Let 
$$X = \{ f\in C([0,1]) | f(0) = 0\}$$ and define $M = N\cap X$, meaning that
$$M = \bigg\{ f\in C([0,1]) | f(0) = 0,  \int_0^1 f(x)dx = 0\bigg\}.$$
Also if 
$u\in C([0,1])$ then 
$$d(x,N) = \inf_{n\in N}||u-n|| = |\bar{u}|$$
where $|\bar{u}| = |\int_0^1 u(x) dx|$ is the mean of u, so the infimum is attained when $n = u-\bar{u}\in N$.
If $u(x) = x\in X$, show that 
$$d(x,M) = \inf_{m\in M} ||u-m|| = \frac{1}{2} $$but that the infimum is not attained for any $m\in M$. 
To prove that $1/2\leq d(u,M)$ is simple. For the other direction we can construct a sequence of functions that helps to show that $1/2\geq d(u,M)$.
My question is, is there an elegant way for doing this? 
Or if not is there an elegant sequence of functions for this?
 A: I don't know if the sequence of functions I will show can be considered "elegant", but it is simple, at least. 

We know the function in $N$ which minimizes the distance w.r.t $u$ is $u-\bar{u}$ with $\bar{u}=\int_0^1 xdx=\frac{1}{2}$. Also $\Vert u-(u-\bar{u})\Vert =\vert \bar{u}\vert =1/2$. 
The idea is to approach $u-\bar{u}$ by piecewise linear and continuous functions in $M$. Consider the following sequence of functions: 
$$
u_n(x)=
\begin{cases}
-nx & x\in[0,1/2n]\\
\frac{n}{n-1}(x-1/2) & x\in[1/2n,1/2]\\
x-1/2 & x\in[1/2,1]
\end{cases}
$$
Clearly $u_n\in X$ for all $n$. Notice 
$$
\int_0^{1/2n}u_n(x)dx=-n\int_0^{1/2n}xdx=-\frac{1}{8n}
$$
and 
\begin{eqnarray}
\int_{1/2n}^{1/2}u_n(x)dx & = & \frac{n}{n-1}\int_{1/2n}^{1/2}(x-1/2)dx\\
& = & \frac{n}{n-1}\left(\frac{1}{8}-\frac{1}{8n^2}-\frac{1}{4}+\frac{1}{4n}\right)\\
& = & -\frac{n}{8(n-1)}\left(\frac{n-1}{n}\right)^2\\
& = & \frac{-n+1}{8n}
\end{eqnarray}
so 
$$
\int_0^{1/2} u_n(x)dx=-1/8=-\int_{1/2}^1 u_n(x)dx
$$
so $u_n\in M$.
Finally, $\Vert u-u_n\Vert = \vert u(1/2n)-u_n(1/2n)\vert=1/2+1/2n$. This shows, for all $n$, $d(u,M)<1/2+1/n$, so $d(u,M)\leq 1/2$.
