To view solutions, see the file 2d-arrays.py
in your text editor.
Context:
Given a 6 X 6
2D Array, A
:
1 1 1 0 0 0
0 1 0 0 0 0
1 1 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
We define an hourglass in A
to be a subset of values with indices falling in this pattern in A
's graphical
representation:
a b c
d
e f g
There are 16
hourglasses in A
, and an hourglass sum is the sum of an hourglass' values.
Task:
Calculate the hourglass sum for every hourglass in A
, then print the maximum hourglass sum.
Input Format
There are 6
lines of input, where each line contains 6
space-separated integers describing 2D Array A
;
every value in A
will be in the inclusive range of -9
to 9
.
Constraints
-9 <= A[i][j] <= 9
0 <= i,j <= 5
Output Format
Print the largest (maximum) hourglass sum found in A
.
Sample 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
Sample Output
19
Solution:
In 2d-arrays.py
.
Return to navigation list