Sort by

recency

|

3700 Discussions

|

  • + 0 comments

    When working with a 2D array, it’s fascinating how the data structure can be used beyond typical programming logic, even for something creative like aesthetic drawing. Each element in the array can represent a pixel, color value, or pattern detail, allowing intricate designs to emerge from organized data. By mapping numerical values to visual elements, a 2D array can essentially become a digital canvas where shapes, gradients, and patterns take form with precision.

    This approach bridges logic and creativity, transforming mathematical structure into visual art. Whether it’s generating symmetrical patterns, pixel-style illustrations, or experimenting with color combinations, the versatility of a 2D array provides a solid foundation for creating aesthetic drawing projects in a programmatic way.

  • + 0 comments

    c#

    public static int hourglassSum(List> arr) { int max=Int32.MaxValue*-1;

        for(int v=0;v<4;v++){
            for(int h=0;h<4;h++){
    
                int sum = 0;
    
                sum += arr[v][h]   + arr[v][h+1]   + arr[v][h+2];
                sum +=               arr[v+1][h+1];
                sum += arr[v+2][h] + arr[v+2][h+1] + arr[v+2][h+2]; 
    
                if(sum>max)
                {
                    max=sum;
                }               
            }
        }
    
        return max;
    }
    
  • + 0 comments

    def hourglassSum(arr): result=-float("inf")

    for pos in range(4):
        for row in range(4):
            total=0
            for col in range(pos,pos+3):
                total+=arr[row][col]+arr[row+2][col]
            total+=arr[row+1][pos+1]
            result=max(total,result)
    
    return result
    
  • + 0 comments
    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    
    #
    # Complete the 'hourglassSum' function below.
    #
    # The function is expected to return an INTEGER.
    # The function accepts 2D_INTEGER_ARRAY arr as parameter.
    #
    
    def hourglassSum(arr):
        arrsum = []
        def hourglass(arr,i,j):
            hg = []
            for n in range(3): 
                if j + n >= len(arr[0]):
                    return []
                else:
                    hg.append(arr[i][j+n])
                    print(arr[i][j+n])
                    
            if i + 1 >= len(arr):
                return []
            else:
                hg.append(arr[i+1][j+1])
                print(arr[i+1][j+1])
            
            if i + 2 < len(arr):
                for n in range(3): 
                    hg.append(arr[i+2][j+n])
            else:
                return []
            return hg
            
        for i in range (len(arr)):
            for j in range (len(arr[0])):                    
                hg =  hourglass(arr,i,j)
                if hg != []:
                    arrsum.append(sum(hg))
                    
                    
        return max(arrsum)
                    
        
                
    
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        arr = []
    
        for _ in range(6):
            arr.append(list(map(int, input().rstrip().split())))
    
        result = hourglassSum(arr)
    
        fptr.write(str(result) + '\n')
    
        fptr.close()
    
  • + 0 comments

    Java code:

    public static int hourglassSum(List> arr) {

    int maxSum = Integer.MIN_VALUE;
    
    for(int i=0;i<4;i++) {
            for(int j=0;j<4;j++) {
                    int sum = arr.get(i).get(j) + arr.get(i).get(j+1) + arr.get(i).get(j+2) 
                                    + arr.get(i+1).get(j+1) 
                            + arr.get(i+2).get(j) + arr.get(i+2).get(j+1) + arr.get(i+2).get(j+2);
    
                    if(sum > maxSum) {
                            maxSum = sum;
                    }
            }
        }
        return maxSum;
    }