Skip to content

Instantly share code, notes, and snippets.

@netchampfaris
Created May 26, 2019 10:42
Show Gist options
  • Save netchampfaris/6f5e76cd7527bdc88de95878d3b3405e to your computer and use it in GitHub Desktop.
Save netchampfaris/6f5e76cd7527bdc88de95878d3b3405e to your computer and use it in GitHub Desktop.
arr = [
[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],
]
def get_hour_glass(i, j):
hour_glass_indices = [
(i, j),
(i, j + 1),
(i, j + 2),
(i + 1, j + 1),
(i + 2, j),
(i + 2, j + 1),
(i + 2, j + 2)
]
return sum([arr[m][n] for m, n in hour_glass_indices])
def get_max_sum():
max_sum = -2**10
for i in range(0, len(arr) - 2):
n = len(arr[i]) - 2
for j in range(0, n):
hour_glass_sum = get_hour_glass(i, j)
if hour_glass_sum > max_sum:
max_sum = hour_glass_sum
@ammarshaikh123
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment