Welcome to Project Lovelace! We're still super new so there are still tons of bugs to find and improvements to make. If you have any suggestions, complaints, or any comments at all please let us know on Discourse!

Correlation does not imply causation

You will learn about:
lists, summing lots of numbers.

Two variables are correlated if there's some statistical relationship between the two. However, just because two variables are correlated does not mean that one is caused by the other. This misconception is commonly referred to as “correlation does not imply causation”.

One way of computing a correlation coefficient between two variables $X$ and $Y$ with $n$ measurements $x_1, x_2, \dots, x_n$ and $y_1, y_2, \dots, y_n$ is the Pearson correlation coefficient
$$r = \frac{\operatorname{cov}(X,Y)}{\sigma_X\sigma_Y}$$
where
$$\operatorname{cov}(X,Y)
= \sum_{i=1}^n (x_i - \overline{x})(y_i - \overline{y})
= (x_1-\overline{x})(y_1-\overline{y}) + \cdots + (x_n-\overline{x})(y_n-\overline{y})$$
is the covariance between $X$ and $Y$,
\begin{align}
\sigma_X
& = \sqrt{\sum_{i=1}^n (x_i - \overline{x})^2}
= \sqrt{(x_1 - \overline{x})^2 + \cdots + (x_n-\overline{x})^2}
\quad \text{and} \\
\sigma_Y
& = \sqrt{\sum_{i=1}^n (y_i - \overline{y})^2}
= \sqrt{(y_1 - \overline{y})^2 + \cdots + (y_n-\overline{y})^2}
\end{align}
are the variances of $X$ and $Y$, and
$$\overline{x}
= \frac{1}{n} \sum_{i=1}^n x_i
= \frac{x_1 + x_2 + \cdots + x_n}{n}
\quad \text{and} \quad
\overline{y}
= \frac{1}{n} \sum_{i=1}^n y_i
= \frac{y_1 + y_2 + \cdots + y_n}{n}$$
are the averages (or means) of the $X$ and $Y$ measurements. The Pearson correlation coefficient $r$ is always between -1 and 1.

Taking in two lists of measurements $x_n$ and $y_n$, return the Pearson correlation coefficient for them.

Input:
Two lists $x_n$ and $y_n$ of size $n$.

Output:
The Pearson correlation coefficient $r$ between the two variables.

Write a function that accepts the input as function parameters and returns the correct output. Make sure to read the description above to produce the correct output in the correct format and use the correct function signature so we can run your code. A good first step is to try reproducing the example(s). Your code must not take longer than the maximum runtime to run and must not use more memory than the allowed limit.

You must be logged in to view your submissions.

There are some really good websites for this stuff.

Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able view the discussion thread below. Feel free to post your solutions but please do your best to organize and document your code well so others can learn from it.