Sort by

recency

|

1936 Discussions

|

  • + 0 comments

    python 3

    !/bin/python3

    import math import os import random import re import sys

    if name == 'main':

    arr = []
    
    for _ in range(6):
        arr.append(list(map(int, input().rstrip().split())))
    results=[]
    for i in range(0,4):
        for j in range(0,4):
            r=(arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2])     
            results.append(r)       
    print(max(results))
    
  • + 0 comments
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    
    if __name__ == '__main__':
        a = []
        for _ in range(6):
            a.append(list(map(int, input().rstrip().split())))
        row=len(a)
        R=[]
        for i in range(row-2):
            for j in range(row-2):
                R.append(a[i][j]+a[i][j+1]+a[i][j+2]+a[i+1][j+1]+a[i+2][j]+a[i+2][j+1]+a[i+2][j+2])
        print(max(R))
    
  • + 0 comments

    python 3

    row= len(arr) p=row-2 n=[]

    while len(n)<=(p*p):
        for i in range(p):
            for j in range(p):
    
                summ=(arr[i][j]+arr[i][j+1]+arr[i][j+2])+(arr[i+1][j+1])+(arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2])
    
                n.append(summ)
    
    print(max(n))
    
  • + 0 comments

    JS

    function main() {
    
        let arr = Array(6);
    
        for (let i = 0; i < 6; i++) {
            arr[i] = readLine().replace(/\s+$/g, '').split(' ').map(arrTemp => parseInt(arrTemp, 10));
        }
        
        var hgSum = -9 * 7; //smallest possible hourglass sum
        
        //loop through the lines until the hourglass is reaching the bottom
        for (let l = 0; l < arr.length-2; l++){
            const arrLine = arr[l];
            
            //loop through the line until the top of the hourglass reaches the end of the line
            for (let i = 0; i < arr[l].length - 2; i++){
                var hourglass = arrLine.slice(i,i+3); //hourglass top
                hourglass.push(arr[l+1][i+1]); //hourglass waist
                hourglass.push(...arr[l+2].slice(i,i+3));//hourglass bottom
                // console.log(hourglass);
                
                var tempSum = hourglass.reduce((a,b) => a + b);
                // console.log(tempSum);
                if (tempSum > hgSum){
                    hgSum = tempSum;
                    }
                }
            }
            console.log(hgSum);
        }
    
  • + 0 comments

    It is worth noting that you can also solve this with convolutions, which could be helpful on huge arrays, since they can be solved with an fft in nlogn time.