Finding distance of $h(t)=t$ from a closed subspace $Y$ of $\pi$-periodic functions in $L^2(-\pi,\pi)$ 
Let $Y=\{f\in L^2(-\pi,\pi):f(t-\pi)=f(t) \text{for almost all $t\in(0,\pi)$} \}$
Show that there exists $g\in Y$ such that $$\|h-g\|_2=\inf \{\|h-f\|_2:f\in Y\}$$
where $h(t)=t$. Compute $\|h-g\|_2$ and specify $g$

I'm struggling with the second part. For the first half of the question, it is enough to show that $Y$ is a closed subspace of $L^2(-\pi,\pi)$.
My guess is that the distance is $\sqrt{\pi^3/2}$, achieved when $g=t-\pi/2$ on $(0,\pi)$. But so far my attempts on proving this led me to messy computations of integrals that didn't seem very promising.
I also think that there should be some easy solution to this, one which somehow manipulates inner products in nice ways.
Any helps appreciated
 A: The orthogonal complement of $Y$ consists of all $g$ such that
$$
       0 = (f,g) = \int_{-\pi}^{0}f(t)\overline{g(t)}+\int_{0}^{\pi}f(t)\overline{g(t)}dt \\
              = \int_{0}^{\pi}f(t-\pi)\overline{g(t-\pi)}+f(t)\overline{g(t)}dt \\
        = \int_{0}^{\pi}f(t)\overline{\{g(t-\pi)+g(t)\}}dt,\;\;\; f \in Y.
$$
It follows that
$$
      Y^{\perp} = \{ g \in L^2 : g(t-\pi)=-g(t) \}.
$$
To find $g\in Y$ as stated, it is necessary and sufficient that
$$
               (t-g(t))\perp Y \\
               (t-g(t)) \in Y^{\perp} \\
               (t-\pi-g(t-\pi))=-(t-g(t)),\;\;\; t \in [0,\pi] \\
               2t-\pi = g(t-\pi)+g(t),\;\;\; t \in [0,\pi] \\
               2t-\pi = 2g(t),\;\;\; t\in [0,\pi] \\
               g(t) = t-\frac{\pi}{2},\;\;\; t \in [0,\pi] \\
               g(t-\pi)=g(t),\;\;\; t \in [-\pi,0).
$$
Therefore the square distance is
$$
      \|t-g\|^2 = \int_{-\pi}^{0}|t-g(t)|^2dt+\int_{0}^{\pi}|t-g(t)|^2dt \\
        =\int_{0}^{\pi}|t-\pi-g(t-\pi)|^2dt+\int_{0}^{\pi}|t-(t-\pi/2)|^2dt \\
        =\int_{0}^{\pi}|t-\pi-g(t)|^2dt+ \pi\frac{\pi^2}{4} \\
        =\int_{0}^{\pi}|t-\pi-(t-\pi/2)|^2dt+\frac{\pi^3}{4} \\
        =\frac{2\pi^3}{4}.
$$
Hence, as you expected, the distance from $t$ to $Y$ is $\sqrt{\pi^3/2}$.
A: Using your $g(t) = t - \frac{\pi|{2}, for\, t > 0$, and $g(t) = t +\frac{\pi}{2}\,for\, t< 0$,
We have $$g(t) - t = -\frac{\pi}{2}\, for\, t > 0 $$ and
$$g(t) - t = \frac{\pi}{2} \, for\, t < 0$$
So (g(t) - t) is odd function.
so $$\int_{_pi}^{\pi} s(t)(g(t) - t)dt = 0 $$, for any $s \in Y$
For any $f \in Y$, we have $\int_{-\pi}^{\pi}f (g -h) dt = 0  = <g-h, f>$ (multiply by odd constant function)
So $$<f-h, f-h> = <f-g, f-g> + <g-h, g-h> \ge <g-h, g-h>$$
The minimum reaches at f(t) = g(t).
$$||g-h||^2 = \int_{-\pi}^{\pi}\frac{\pi^2}{4}dt = \frac{\pi^3}{2}$$ 
