Created
November 29, 2015 19:17
-
-
Save jamesmintram/d0b0e60e5513a7297612 to your computer and use it in GitHub Desktop.
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
(defn diag-diff | |
[data] | |
(let [width (Math/sqrt (count data)) | |
right-seq (take-nth (+ 1 width) data) | |
right-diag (take width right-seq) | |
left-data (drop (- width 1) data) | |
left-seq (take-nth (- width 1) left-data) | |
left-diag (take width left-seq) | |
right-sum (reduce + 0 right-diag) | |
left-sum (reduce + 0 left-diag) | |
] | |
(- left-sum right-sum) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment