[OT] fastest fibbonacci
Minas Mina via Digitalmars-d
digitalmars-d at puremagic.com
Sun Oct 23 12:59:16 PDT 2016
On Sunday, 23 October 2016 at 13:04:30 UTC, Stefam Koch wrote:
> Hi Guys,
>
> while brushing up on my C and algorithm skills, accidently
> created a version of fibbonaci which I deem to be faster then
> the other ones floating around.
>
> It's also more concise
>
> the code is :
>
> int computeFib(int n)
> {
> int t = 1;
> int result = 0;
>
> while(n--)
> {
> result = t - result;
> t = t + result;
> }
>
> return result;
> }
You can even calculate Fibonacci in O(1).
More information about the Digitalmars-d
mailing list