Skip to content

Instantly share code, notes, and snippets.

@clauswitt
Created July 4, 2011 11:28
Show Gist options
  • Select an option

  • Save clauswitt/1063238 to your computer and use it in GitHub Desktop.

Select an option

Save clauswitt/1063238 to your computer and use it in GitHub Desktop.
Euler6.js
var sys = require('sys');
var Euler6 = function() {
var getSquareOfSum = function(max) {
res = 0;
for(var i=1;i<=max;i++) {
res += i;
}
res = res*res;
return res;
}
var getSumOfSquares = function(max) {
res = 0;
for(var i=1;i<=max;i++) {
res += i*i;
}
return res;
}
var getResult = function(max) {
sumOfSquares = getSumOfSquares(max);
squareOfSums = getSquareOfSum(max);
difference = squareOfSums - sumOfSquares;
sys.puts('Difference: ' + difference);
}
getResult(100);
};
new Euler6();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment