Skip to content

Instantly share code, notes, and snippets.

@alexbaldwin
Created July 8, 2012 23:19
Show Gist options
  • Save alexbaldwin/3073396 to your computer and use it in GitHub Desktop.
Save alexbaldwin/3073396 to your computer and use it in GitHub Desktop.
Project Euler Problem 6
var squarer = function(solvingFor) {
var squares = [];
for (i=0; i <= solvingFor; i++){
var squared = i * i;
squares.push(squared);
}
var total = 0;
for (i = 0; i < squares.length; i++ ) {
total = total + squares[i];
}
console.log(total);
return total;
};
var toSquare = function(solvingFor) {
var numbers = [];
for (i=0; i <= solvingFor; i++){
numbers.push(i);
}
var total = 0;
for (i = 0; i < numbers.length; i++ ) {
total = total + numbers[i];
}
total = total * total;
console.log(total);
return total;
};
var squareSum = function(x) {
return toSquare(x) - squarer(x);
};
console.log(squareSum(100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment