Ejemplo n.º 1
0
        public Day5()
        {
            Input = AdventOfCodeService.GetInput(2018, 5).Trim();

            Part1();
            Part2();
        }
Ejemplo n.º 2
0
        public Day1()
        {
            _input = AdventOfCodeService.GetInput(2019, 1).AsListOf <int>();

            Part1();
            Part2();
        }
Ejemplo n.º 3
0
        public Day2()
        {
            _input = AdventOfCodeService.GetInput(2018, 2).AsListOf <string>();

            Part1();
            Part2();
        }
Ejemplo n.º 4
0
        public Day8()
        {
            var input = AdventOfCodeService.GetInput(2018, 8).AsListOf <int>(" ");

            Root = ParseNode(input);

            Part1();
            Part2();
        }
Ejemplo n.º 5
0
        public Day6()
        {
            _input = AdventOfCodeService.GetInput(2018, 6).AsListOf <string>().Select(s => new XY(s)).ToList();

            _width  = _input.Max(p => p.X);
            _height = _input.Max(p => p.Y);

            Part1();
            Part2();
        }
Ejemplo n.º 6
0
        public Day4()
        {
            var input = AdventOfCodeService.GetInput(2018, 4).AsListOf <string>();

            _logs = input.Select(ParseLog).OrderBy(log => log.Time).ToList();

            int prevId = 0;

            foreach (var log in _logs)
            {
                if (log.Status == LogType.BeginsShift)
                {
                    prevId = log.GuardId;
                    continue;
                }

                log.GuardId = prevId;
            }

            _guardSleepMinutes = new Dictionary <int, List <int> >();

            var lastAsleep = new DateTime();

            foreach (var log in _logs)
            {
                if (log.Status == LogType.BeginsShift)
                {
                    if (!_guardSleepMinutes.ContainsKey(log.GuardId))
                    {
                        _guardSleepMinutes.Add(log.GuardId, new List <int>());
                    }
                }
                else if (log.Status == LogType.FallsAsleep)
                {
                    lastAsleep = log.Time;
                }
                else if (log.Status == LogType.WakesUp)
                {
                    var mins = log.Time.Subtract(lastAsleep).TotalMinutes;
                    for (int i = 0; i < mins; i++)
                    {
                        _guardSleepMinutes[log.GuardId].Add(lastAsleep.AddMinutes(i).Minute);
                    }
                }
            }

            Part1();
            Part2();
        }
Ejemplo n.º 7
0
        public Day7()
        {
            Instructions = AdventOfCodeService.GetInput(2018, 7).AsListOf <string>()
                           .Select(s => s.Split(' ').Where(s1 => s1.Length == 1 && char.IsUpper(s1[0])).ToArray())
                           .Select(strings => new Instr(strings[0][0], strings[1][0]))
                           .ToList();

            setup();


            Part1();

            setup();

            Part2();
        }
Ejemplo n.º 8
0
        public Day3()
        {
            var input = AdventOfCodeService.GetInput(2018, 3).AsListOf <string>();

            var regex = new Regex(@"([0-9]\d*)");

            _claims = input.Select(s =>
            {
                var matches = regex.Matches(s);
                return(new Claim
                {
                    id = matches[0].Value,
                    pos = new Tuple <int, int>(int.Parse(matches[1].Value), int.Parse(matches[2].Value)),
                    size = new Tuple <int, int>(int.Parse(matches[3].Value), int.Parse(matches[4].Value))
                });
            }
                                   ).ToList();

            Part1();
            Part2();
        }
Ejemplo n.º 9
0
 public Day2()
 {
     _input = AdventOfCodeService.GetInput(2019, 2).AsListOf <int>(",");
 }