Skip to content

Instantly share code, notes, and snippets.

@vivanov1410
Created August 5, 2012 07:08
Show Gist options
  • Select an option

  • Save vivanov1410/3262553 to your computer and use it in GitHub Desktop.

Select an option

Save vivanov1410/3262553 to your computer and use it in GitHub Desktop.
Exercise #1
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
@qd39
Copy link

qd39 commented Aug 9, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment