Created
May 22, 2016 23:55
-
-
Save mcleary/41d8f85ab78c7f6513018c4a72142759 to your computer and use it in GitHub Desktop.
Diagonal Difference
This file contains hidden or 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
M = [[11, 2, 4], [4, 5, 6], [10, 8, -12]] | |
main_diag = 0 | |
sec_diag = 0 | |
for i in 0..2 | |
main_diag += M[i][i] | |
sec_diag += M[i][3 - i - 1] | |
end | |
puts "Main Diag: " + main_diag.to_s | |
puts "Sec Diag: " + sec_diag.to_s | |
puts (main_diag - sec_diag).abs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment