• + 1 comment

    my solution for C (Sorry if it's messy, I'm fairly new to this):

    (for testcases 3 & 7, maxsum is negative, so make sure it is not initilized to zero. I initilized to the first hourglass sum)

    int main() {
    int a[6][6], i, j, k, m, sum, maxsum;  
    for (i = 0; i < 6; i++){
        for (j = 0; j < 6 ; j++){
            scanf("%d", &a[i][j]);
        }
    }
    
    maxsum = a[0][0]+a[0][1]+a[0][2]+a[1][1]+a[2][0]+a[2][1]+a[2][2]; //sum of first hourglass
    
    for (i = 0; i < 4; i++){ // i is the top row of hourglass
    
      for (j = 0; j < 4; j++){ //moves hourglass one to right
    
          sum = 0; //resets sum for new hourglass
    
          for (k = j; k < j+3; k++){ // value for column
    
              sum += a[i][k]; //sum of first row
    
              if (k == j+1){ // middle row of hourglass
                  sum += a[i+1][k]; //sum of middle row
              }
    
              m = i+2; // third row of hourglass
              sum += a[m][k]; //sum of third row
          }
    
        if (sum > maxsum){ // if new sum is greater than maxsum
    
              maxsum = sum; // sum becomes the new maxsum
        }
      }
     }
      printf("%d", maxsum);
    }
    

    (indentention got messed up @ end when copypaste, sry)