mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
21 lines
362 B
Python
21 lines
362 B
Python
#!/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)
|
|
|