matrix and fibonacci

newcomer[bob] bob at dontknow.com
Thu Mar 8 21:50:02 PST 2012


The following is a matrix implementation of the fibonacci
algorithm:

int fib(int n)
{
      int M[2][2] = {{1,0},{0,1}}
      for (int i = 1; i < n; i++)
          M = M * {{1,1},{1,0}}
      return M[0][0];
   }

problem is I don't really understand how matrix multiplication
works so i cannot translate it to an equivalent solution in D.
Thank for you assistance in advance.

newcomer[bob]


More information about the Digitalmars-d-learn mailing list