4 ms·
Very neat. Picking up the exponentiation by squaring algorithm for free by implementing Semigroup is a really nice touch. Since you're defining your own custom
by olooney 7y ago
Very neat. Picking up the exponentiation by squaring algorithm for free by implementing Semigroup is a really nice touch.
Since you're defining your own custom Matrix2x2 class and <> operation anyway, you can save a little space and computation by relying on the fact that every Fibonacci matrix is of the form: [ a+b, a; a, b ]. Thus only two member variables are needed, and <> can be implemented with fewer multiplications.