Problem 6

Sum square difference

The sum of the squares of the first ten natural numbers is,

The square of the sum of the first ten natural numbers is,

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is .
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.


https://projecteuler.net/problem=6

Brute Force

function sum(arr) {
  return arr.reduce(function(n, sum) { return sum + n; }, 0);
}

function square(n) {
  return Math.pow(n, 2);
}

function sumSquares(arr) {
  return sum(arr.map(square));
}

function squareSums(arr) {
  return square(sum(arr));
}

function euler6() {
  return squareSums(range(1,100)) - sumSquares(range(1,100));
}
timer(euler6);
// euler6 x 1: 0.078ms
// 25164150