/Hourglass-Go

Given a 2D matrix, the task is to find the maximum sum of an hourglass. This is my Go implementation.

Primary LanguageGo

Hourglass-Go

Given a two-digit array, the task is to find the maximum sum of an hourglass shape

Overview

In a two-digit array, this collection of numbers make an hourglass shape

a b c
  d
e f g

Sample Input

There are a total of 16 hourglass shapes found in the sample input data

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

Explanation

The "sample input" data contains the following 16 hourglasses.

1 1 1    1 1 0    1 0 0    0 0 0
  1        0        0        0
1 1 1    1 1 0    1 0 0    0 0 0

0 1 0    1 0 0    0 0 0    0 0 0
  1        0        0        0
0 0 2    0 2 4    2 4 4    4 4 0

1 1 1    1 1 0    1 0 0    0 0 0
  0        2        4        4
0 0 0    0 0 2    0 2 0    2 0 0

0 0 2    0 2 4    2 4 4    4 4 0
  0        0        2        0
0 0 1    0 1 2    1 2 4    2 4 0

The sum of the largest hourglass found in the input data is 19.

2 4 4
  2
1 2 4

For example 2 + 4 + 4 + 2 + 1 + 2 + 4 = 19

Contact

You can contact me via gmail or at my website http://www.richardhollon.com or find me on LinkedIn