SHARE
TWEET

Untitled

a guest May 27th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ArrayStuff
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             var arr = new int[6][]
  11.             {
  12.                new []{1,1,1,0,0,0},
  13.                new []{0,1,0,0,0,0},
  14.                new []{1,1,1,0,0,0},
  15.                new []{0,0,-2,4,-4,0},
  16.                new []{0,0,0,2,0,0},
  17.                new []{0,0,1,2,4,0}
  18.             };
  19.             var result = hourglassSum(arr);
  20.             Console.WriteLine(result);
  21.             Console.ReadLine();
  22.         }
  23.  
  24.  
  25.         static int hourglassSum(int[][] arr)
  26.         {
  27.             int winningAddition = 0;
  28.             for (int i = 0; i <= 3; i++)
  29.             {
  30.                 for (int j = 0; j <= 3; j++)
  31.                 {
  32.                     var topHourglass = GetTopHourGlass(arr,i,j);
  33.                     var middleHourglass = arr[i + 1][j + 1];
  34.                     var bottomHourglass = GetBottomHourGlass(arr,i,j);
  35.  
  36.                     var result = topHourglass.Sum() + middleHourglass + bottomHourglass.Sum();
  37.                     if (result > winningAddition)
  38.                     {
  39.                         winningAddition = result;
  40.                     }
  41.                 }
  42.             }
  43.            
  44.             return winningAddition;
  45.            
  46.         }
  47.  
  48.         private static int[] GetBottomHourGlass(int[][] arr, int i, int j)
  49.         {
  50.            // i +2 j +2
  51.  
  52.            var newArray = arr[i +2].Skip(j).Take(3).ToArray();
  53.            return  newArray;
  54.  
  55.         }
  56.  
  57.         private static int[] GetTopHourGlass(int[][] arr,int i,int j)
  58.         {
  59.             var newArray = arr[i].Skip(j).Take(3).ToArray();
  60.  
  61.             return  newArray;
  62.         }
  63.     }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top