Created
April 17, 2023 21:17
-
-
Save kevinah95/6c1668b6a3afd68025b0e0b57f81dc2a to your computer and use it in GitHub Desktop.
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
def hourglassSum(arr): | |
results = [] | |
max_value = 0 | |
for j in range(4): | |
sums = [] | |
for i in range(5): | |
sum_01 = sum(arr[j][i : 3 + i]) | |
sum_02 = arr[j + 1][i + 1] | |
sum_03 = sum(arr[j + 2][i : 3 + i]) | |
sums.append(sum_01 + sum_02 + sum_03) | |
max_of_sums = max(sums) | |
if max_of_sums >= max_value: | |
max_value = max_of_sums | |
results.append(sums) | |
print(results) | |
return max_value | |
input = [ | |
[1, 1, 1, 0, 0, 0], | |
[0, 1, 0, 0, 0, 0], | |
[1, 1, 1, 0, 0, 0], | |
[0, 0, 2, 4, 4, 0], | |
[0, 0, 0, 2, 0, 0], | |
[0, 0, 1, 2, 4, 0], | |
] | |
r = hourglassSum(input) | |
print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment