This notebook was prepared by Donne Martin. Source and license info is on GitHub.
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
class Matrix(object):
def __init__(self, first, second):
self.first = first
self.second = second
class MatrixMultiplicationCost(object):
def find_min_cost(self, matrices):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_find_min_cost.py
import unittest
class TestMatrixMultiplicationCost(unittest.TestCase):
def test_find_min_cost(self):
matrix_mult_cost = MatrixMultiplicationCost()
self.assertRaises(TypeError, matrix_mult_cost.find_min_cost, None)
self.assertEqual(matrix_mult_cost.find_min_cost([]), 0)
matrices = [Matrix(2, 3),
Matrix(3, 6),
Matrix(6, 4),
Matrix(4, 5)]
expected_cost = 124
self.assertEqual(matrix_mult_cost.find_min_cost(matrices), expected_cost)
print('Success: test_find_min_cost')
def main():
test = TestMatrixMultiplicationCost()
test.test_find_min_cost()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.