Skip to content

Instantly share code, notes, and snippets.

@codelance
Created December 2, 2012 01:10
Show Gist options
  • Save codelance/4186310 to your computer and use it in GitHub Desktop.
Save codelance/4186310 to your computer and use it in GitHub Desktop.
Fibonacci
private static int gfib(int f0, int f1, int n)
{
switch( n )
{
case 0:
return f0;
case 1:
return f1;
default:
return gfib(f0,f1, n-1 ) + gfib(f0, f1, n+1);
}
}
private static int itergfib(int f0, int f1, int n)
{
int sum = 0;
for(int i = n; i <= 0; i--)
{
if( n == 0 ) sum += f0;
if( n == 1) sum += f1;
sum += (n-1) + (n-2);
}
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment