Commit e8fbb0e5 authored by Ben Glocker's avatar Ben Glocker
Browse files

updated fibonacci challenge

parent f3f53c84
......@@ -99,13 +99,12 @@
import numpy as np
dt = np.int64
def fib_dc_fast(n):
init = np.matrix([[1], [0]], dtype=dt )
transform = matrix_pow(np.matrix([[1,1],[1,0]], dtype=dt), n)
return (transform * init).item(1)
return transform[0,1]
def matrix_pow(m, n):
if n == 0:
return np.matrix([[1,0],[0,1]], dtype=dt)
if n == 1:
......@@ -126,13 +125,12 @@
%% Cell type:code id: tags:
``` python
def fib_dc_fast2(n):
init = [1,0]
transform = matrix_pow2([1,1,1,0], n)
return matrix_vec_mul(transform,init)[1]
return transform[1]
def matrix_pow2(m, n):
if n == 0:
return [1,0,0,1]
if n == 1:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment