Created
August 5, 2012 07:08
-
-
Save vivanov1410/3262553 to your computer and use it in GitHub Desktop.
Exercise #1
This file contains hidden or 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
| fibb_even_sum = (limit) -> | |
| sum = 0 | |
| a = 1 | |
| b = 1 | |
| c = a + b | |
| while c <= limit | |
| sum += c | |
| a = b + c | |
| b = a + c | |
| c = a + b | |
| return sum | |
| console.log fibb_even_sum 4000000 | |
| >> 4613732 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
public int sum(int x,int y)
{
return x + y;
}
public int foo()
{
var currentNum = 2;
var lastNum = 1;
var totalSum = 0;
while(currentNum < 4000000)
{
if(lastNum > 0 && currentNum > 0){
if(currentNum % 2 == 0)
totalSum += currentNum;
var newNum = sum(lastNum, currentNum);
lastNum = currentNum;
currentNum = newNum;
}
}
return totalSum;
}
// Run on https://compilify.net/
// CPU Time: 00:00:00.0156001
// Bytes Allocated: 80 KB