Ejemplo n.º 1
0
        static Object PartA()
        {
            var       input = ReadIndata.Longs(inputPath);
            long      ans   = 0;
            bool      found = true;
            const int n     = 25;
            int       t     = n;

            while (found)
            {
                found = false;
                ans   = input[t];
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if ((i != j) && (input[t - n + i] + input[t - n + j] == ans))
                        {
                            found = true;
                        }
                    }
                }
                t++;
            }
            Console.WriteLine("Part A: Result is {0}", ans);
            return(ans);
        }
Ejemplo n.º 2
0
        static Object PartB()
        {
            var        input = ReadIndata.Longs(inputPath);
            long       ans   = 0;
            const long tgt   = 167829540;
            int        t     = 0;

            while (ans <= 0)
            {
                long sum = 0;
                int  n   = 0;
                for (n = 0; n < 2 || sum < tgt; n++)
                {
                    sum += input[t + n];
                }
                if (sum == tgt)
                {
                    var r = input.Skip(t).Take(n).ToList();
                    ans = r.Min() + r.Max();
                }
                t++;
            }
            Console.WriteLine("Part B: Result is {0}", ans);
            return(ans);
        }
Ejemplo n.º 3
0
        static Object PartB()
        {
            List <long> input = ReadIndata.Longs(inputPath);

            input.Sort();
            long ans = 0;

            for (int i = 0; i < input.Count; i++)
            {
                for (int j = 0; j < input.Count; j++)
                {
                    if (j != i)
                    {
                        long a = input[i];
                        long b = input[j];
                        long c = 2020 - a - b;
                        if (input.Contains(c))
                        {
                            ans = a * b * c;
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("Part B: Result is {0}", ans);
            return(ans);
        }