Update and rename matrix-sum-diagonals.py to matrix_sum_diagonals.py

This commit is contained in:
marina 2023-08-07 17:33:29 -07:00 committed by GitHub
parent b14d9fcee2
commit 250e136166
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,20 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# author: bt3gl
def diagonal_difference(arr):
diag_1 = 0
diag_2 = 0
i, j = 0, len(arr) - 1
while i < len(arr) and j >= 0:
diag_1 += arr[i][i]
diag_2 += arr[i][j]
i += 1
j -= 1
return diag_1, diag_2, abs(diag_1 - diag_2)