Transpose Me

Submitted By:
Mason

Difficulty:
Medium

Tags:
matrices

Instructions:
Given any two matrices (each represented as an array of arrays, where each subarray represents one row of the matrix), return the product of the two matrices. If no product exists for the two matrices, return nil.

Hidden Code:
There is hidden code with assertions that is also being run to test out your code.

Code:
def matrix_product(left, right)
  ___
end

assert_equal matrix_product([[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[7,10],[15,22]]
assert_equal matrix_product([[1, 2, 3]], [[1], [2], [3]]), [[14]]
assert_equal matrix_product([[1], [2], [3], [4]], [[1], [2], [3]]), nil

Your Solution

Ruby 1.9.3

Back to Problems