Created
April 19, 2015 09:14
-
-
Save anonymous/0f1f67c64fd10043b4bb to your computer and use it in GitHub Desktop.
The learning process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Kata http://www.codewars.com/kata/551204b7509063d9ba000b45/haskell | |
mainDiagonalProduct :: Num a => [[a]] -> a | |
-- My implementation | |
mainDiagonalProduct [] = 1 | |
mainDiagonalProduct mat = | |
mainDiagonalProduct' mat ((length mat) - 1) | |
where | |
mainDiagonalProduct' mat 0 = (head . head) mat | |
mainDiagonalProduct' mat index = | |
((mat !! index) !! index) * (mainDiagonalProduct' mat (index - 1)) | |
-- Good implementation | |
mainDiagonalProduct mat = product $ zipWith (!!) mat [1..] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment