Last active
December 22, 2020 18:17
-
-
Save pawelrubin/62e6d73dcbfe1aa2c86f8e096efc3322 to your computer and use it in GitHub Desktop.
Calculate the absolute difference between the sums of a square matrix diagonals, in Haskell.
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
diagonalDifference :: [[Int]] -> Int | |
diagonalDifference arr = abs . sum $ differences | |
where | |
differences = map (\(i, row) -> (row !! i) - (row !! (len - 1 - i))) (enumerate arr) | |
len = length arr | |
enumerate = zip [0 ..] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment