Beltiras

Árni Steingrímur Sigurðsson

RATING

0.01
Karma: 0.00
avatar
Also, you should memoize the matrix multiplication, that's a heavy step, and one for repeated invocations would save a ton of time.
avatar
Bottom of def get_number renders as the Registered Trademark unicode instead of ®.

You can be a little more concise with the code by modifying how __memo is set up.

def __init__(self):
        self.__memo = {0:0,1:1}


Then you can do:

def __get_matrix_power(self, M, p):
        """Matrix exponentiation (it is expected that p that is equal to the power of 2)."""
        return self.__memo.get(p,self.non_memoized(M,p))

def non_memoized(self, M,p):
        K = self.__get_matrix_power(M, int(p/2))
        R = self.__multiply_matrices(K, K)
        self.__memo[p] = R
        return R


I know it essentially does the same thing, IMHO it's a little cleaner code thou ;)