Exemplo n.º 1
0
        public async Task Part1Async()
        {
            RawInput = await AdventOfCodeHelper.ReadInputForDayAsync(1);

            _numbers = RawInput.Select(x => Convert.ToInt32(x)).ToArray();
            // var numbers = new[] {1721, 979, 366, 299, 675, 1456};

            _expectedTotal = 2020;

            Console.WriteLine("[Day 1] Defined parameters:");
            Console.WriteLine(_numbers);
            Console.WriteLine($"[Day 1] expectedTotal: {_expectedTotal}");

            // Part 1
            Console.WriteLine("[Day 1] Finding pair with sum...");

            var pair = FindPairWithSum(_numbers, _expectedTotal);

            if (pair.HasValue)
            {
                Console.WriteLine($"[Day 1] Pair found: {pair}");
                Console.WriteLine($"[Day 1] Product: {pair.Value.first * pair.Value.second}");
            }
            else
            {
                Console.WriteLine("[Day 1] Pair not found :(");
            }
        }
Exemplo n.º 2
0
        public async Task Part1Async()
        {
            RawInput = await AdventOfCodeHelper.ReadInputForDayAsync(3);

            _treeCountPart1 = CountTrees(SpacesToTheRightFromPart1, 1);

            Console.WriteLine($"[Day 3] Tree count for part 1 is: {_treeCountPart1}!");
        }
Exemplo n.º 3
0
        public static IDay CreateDay(int dayNumber)
        {
            AdventOfCodeHelper.ValidateDayNumber(dayNumber);

            var type = Type.GetType($"ConsoleApp.Day{dayNumber}") ??
                       throw new ArgumentException("Day not available yet!", nameof(dayNumber));

            dynamic instance = Activator.CreateInstance(type) as IDay;

            return(instance);
        }
Exemplo n.º 4
0
        public async Task Part1Async()
        {
            RawInput = await AdventOfCodeHelper.ReadInputForDayAsync(5);

            _planeSeats = new List <PlaneSeat>();

            foreach (var seatStr in RawInput)
            {
                _planeSeats.Add(new PlaneSeat(seatStr));
            }

            Console.WriteLine(_planeSeats.Max(ps => ps.SeatId));
        }
Exemplo n.º 5
0
        public async Task Part1Async()
        {
            RawInput = await AdventOfCodeHelper.ReadInputForDayAsync(2);

            _extractedPasswords = ExtractPasswordRows(RawInput);

            var validPasswordCount = 0;

            foreach (var passwordRow in _extractedPasswords)
            {
                validPasswordCount += Convert.ToInt32(passwordRow.PasswordStringIsValid());
            }

            Console.WriteLine($"[Day 2] {validPasswordCount} valid passwords detected!");
        }