Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 4.34 KB

103-product-of-the-main-diagonal-of-a-square-matrix..md

File metadata and controls

24 lines (19 loc) · 4.34 KB

Problem:

Given a list of rows of a square matrix, find the product of the main diagonal.

Examples:

main_diagonal_product([[1,0],[0,1]]) => 1

main_diagonal_product([[1,2,3],[4,5,6],[7,8,9]]) => 45

mainDiagonalProduct []                        `shouldBe` 1          -- matrix: 0x0
mainDiagonalProduct [[1]]                     `shouldBe` 1          -- matrix: 1x1
mainDiagonalProduct [[1,2,3],[4,5,6],[7,8,9]] `shouldBe` 1 * 5 * 9  -- matrix: 3x3
mainDiagonalProduct([[1,0],[0,1]]) => 1

mainDiagonalProduct([[1,2,3],[4,5,6],[7,8,9]]) => 45
mainDiagonalProduct([[1,0],[0,1]]) => 1

mainDiagonalProduct([[1,2,3],[4,5,6],[7,8,9]]) => 45
main_diagonal_product([[1,0],[0,1]]) => 1

main_diagonal_product([[1,2,3],[4,5,6],[7,8,9]]) => 45
mainDiagonalProduct []                        `shouldBe` 1          -- matrix: 0x0
mainDiagonalProduct [[1]]                     `shouldBe` 1          -- matrix: 1x1
mainDiagonalProduct [[1,2,3],[4,5,6],[7,8,9]] `shouldBe` 1 * 5 * 9  -- matrix: 3x3

http://en.wikipedia.org/wiki/Main_diagonal

Solution