Solution (source code)

= Solution

In a linear model containing an intercept, the normal equations make the residual <vector> $e$ orthogonal to every design column. In particular $e\perp\mathbf1$, so
$$
\sum_{i=1}^{50}e_i=\mathbf1^Te=0
$$
up to floating-point rounding.

The second design <matrix> has $49$ random Gaussian columns plus the intercept, hence is a random $50\times50$ <matrix>. It has full rank with probability one because the <determinant> vanishes only on a measure-zero algebraic set. Its column space is then all of $\mathbb R^{50}$, so the fitted <vector> equals $Y$, the residual sum of squares is zero, and $R^2=1$.