Skip to content

Instantly share code, notes, and snippets.

@clauswitt
Created May 29, 2010 19:01
Show Gist options
  • Save clauswitt/418453 to your computer and use it in GitHub Desktop.
Save clauswitt/418453 to your computer and use it in GitHub Desktop.
var sys = require('sys');
var Euler2 = function() {
var isEven = function(num) {
if((num % 2)==0) return true;
return false;
}
var calcEvenFibonacci = function(max) {
var secondLast = 1;
var last = 2;
var res = 2;
for(i=0;i<max;i++) {
if(i == (secondLast+last)) {
secondLast = last;
last = i;
if(isEven(i)) {
res +=i;
}
}
}
sys.puts('Result: ' + res);
}
calcEvenFibonacci(4000000);
};
new Euler2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment