DEV Community

loading...

Discussion on: Advent of Code 2020 Solution Megathread - Day 1: Report Repair

Collapse
dirkfraanje profile image
Dirk Fraanje (the Netherlands)

My solution in C#: (The timer is just for fun ..)

    public static void Execute()
    {
        var timer = new Stopwatch();
        timer.Start();

        for (int i = 0; i < input.Count; i++)
        {
            for (int i2 = i + 1; i2 < input.Count; i2++)
            {
                var valueneeded = 2020 - input[i] - input[i2];
                if (input.Contains(valueneeded))
                {
                    timer.Stop();
                    Console.WriteLine();
                    Console.WriteLine($"Answer: {input[i] * input[i2] * valueneeded}");
                    Console.WriteLine($"Executed in: {timer.ElapsedMilliseconds} milliseconds, {timer.ElapsedTicks}  Ticks");
                }

            }
        }
    }
Enter fullscreen mode Exit fullscreen mode