mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-22 16:31:15 -04:00
Update and rename matrix-sum-diagonals.py to matrix_sum_diagonals.py
This commit is contained in:
parent
b14d9fcee2
commit
250e136166
1 changed files with 0 additions and 15 deletions
20
arrays_and_strings/matrix_sum_diagonals.py
Normal file
20
arrays_and_strings/matrix_sum_diagonals.py
Normal 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)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue