Created
May 29, 2010 19:01
-
-
Save clauswitt/418453 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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