Exemplo n.º 1
0
        public static string LargeSum(string n)
        {
            string[]          nums = FileFunctions.readfileintostringarr(n);
            List <BigInteger> bigs = FileFunctions.stringarrtobigint(nums);

            return(bigs.Aggregate(BigInteger.Add).ToString());
        }
Exemplo n.º 2
0
 public static int MaximumPathSum1(string n)
 {
     string[] temp = FileFunctions.readfileintostringarr(n);
     int[][]  tri  = FileFunctions.stringtointarraySplit2d(temp, ' ');
     for (int j = tri.GetLength(0) - 2; j >= 0; j--)
     {
         for (int i = 0; i < tri[j].Length; i++)
         {
             tri[j][i] += Math.Max(tri[j + 1][i], tri[j + 1][i + 1]);
         }
     }
     return(tri[0][0]);
 }
Exemplo n.º 3
0
        public static int LargestProductInAGrid(string n, int m)
        {
            int mult = 1;

            string[] strnums = FileFunctions.readfileintostringarr(n);
            int[][]  nums    = FileFunctions.stringtointarraySplit2d(strnums, ' ');
            for (int i = 0; i < nums.Count(); i++)
            {
                for (int j = 0; j < nums[0].Count(); j++)
                {
                    if (i < nums.Count() - m)
                    {
                        int tempmult = 1;
                        for (int k = 0; k < m; k++)
                        {
                            tempmult *= nums[i + k][j];
                        }
                        if (tempmult > mult)
                        {
                            mult = tempmult;
                        }
                    }
                    if (j < nums.Count() - m)
                    {
                        int tempmult = 1;
                        for (int k = 0; k < m; k++)
                        {
                            tempmult *= nums[i][j + k];
                        }
                        if (tempmult > mult)
                        {
                            mult = tempmult;
                        }
                    }
                    if (j < nums.Count() - m && i < nums.Count() - m)
                    {
                        int tempmult = 1;
                        for (int k = 0; k < m; k++)
                        {
                            tempmult *= nums[i + k][j + k];
                        }
                        if (tempmult > mult)
                        {
                            mult = tempmult;
                        }
                    }
                    if (j > m && i < nums.Count() - m)
                    {
                        int tempmult = 1;
                        for (int k = 0; k < m; k++)
                        {
                            tempmult *= nums[i + k][j - k];
                        }
                        if (tempmult > mult)
                        {
                            mult = tempmult;
                        }
                    }
                }
            }
            return(mult);
        }