Solution (source code)

= Solution

The <binomial theorem> states
$$
(x+y)^n=\sum_{r=0}^n\binom nrx^ry^{n-r}.
$$
The required sum is the coefficient of $x^n$ in
$$
(1-x)^n(1+x)^n=(1-x^2)^n.
$$
There is no $x^n$ term when $n$ is <odd number>[odd]. When $n$ is <even number>[even], the relevant term has exponent $2(n/2)=n$ and coefficient $(-1)^{n/2}\binom n{n/2}$. Hence
$$
\sum_{r=0}^n(-1)^r\binom nr^2
=\begin{cases}
0,&n\text{ odd},\\
(-1)^{n/2}\binom n{n/2},&n\text{ even}.
\end{cases}
$$