1, 1, 2, 3, 5, 8...
Website | Twitter | 500px | Facebook | Instagram | Getty
Round and round and round we go..!
If you recognize the sequence then you'll recognize this:
long fib(long n)
{
return n<2 ? 1 : fib(n-1) + fib(n-2);
}
or:
long fib(long n)
{
return n<2 ? n : fib(n-1) + fib(n-2);
}
depending on where you think the sequence starts from.
(Well, you'll recognize it if you know C, C++, C# or Java)
1, 1, 2, 3, 5, 8...
Website | Twitter | 500px | Facebook | Instagram | Getty
Round and round and round we go..!
If you recognize the sequence then you'll recognize this:
long fib(long n)
{
return n<2 ? 1 : fib(n-1) + fib(n-2);
}
or:
long fib(long n)
{
return n<2 ? n : fib(n-1) + fib(n-2);
}
depending on where you think the sequence starts from.
(Well, you'll recognize it if you know C, C++, C# or Java)