Example #1
0
 private static Task <(Rule, string)[]> Parse(string file)
 {
     return(LittleHelper.Parse(file, "\n", line =>
     {
         var s = line.Split(':');
         return (new Rule(s[0]), s[1]);
     }));
Example #2
0
 public static async Task <int> Task1(string file)
 {
     var instructions = await LittleHelper.Parse(file, "\n", l =>
     {
         var instruction = l.Split(' ');
         return(instruction[0], instruction[1]);
     });
Example #3
0
        public static async Task <int> Task1(string file)
        {
            var lines = await LittleHelper.Parse(file, "\n\n", l => l);

            var required = new[] { "byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid" };

            return(lines.Count(line => required.All(line.Contains)));
        }
Example #4
0
        private static async Task <HashSet <int> > GetSeats(string file)
        {
            var lines = await LittleHelper.Parse(file, "\n", s => s);

            var map = new Dictionary <string, string> {
                { "F", "0" }, { "B", "1" }, { "L", "0" }, { "R", "1" }
            };
            var regex = new Regex(string.Join("|", map.Keys));
            var seats = new HashSet <int>();

            foreach (var line in lines)
            {
                var pass = regex.Replace(line, m => map[m.Value]);
                var row  = Convert.ToInt32(pass.Substring(0, 7), 2);
                var col  = Convert.ToInt32(pass.Substring(7, 3), 2);
                var seat = row * 8 + col;
                seats.Add(seat);
            }
            return(seats);
        }
Example #5
0
        public static async Task <int> Task2(string file)
        {
            var lines = await LittleHelper.Parse(file, "\n\n", s => s);

            var count = 0;

            foreach (var line in lines)
            {
                var answers = line.Split("\n", StringSplitOptions.RemoveEmptyEntries)
                              .Select(s => s.ToCharArray())
                              .ToArray();

                count += answers
                         .Skip(1)
                         .Aggregate(answers.First(), (p1, p2) => p1.Intersect(p2).ToArray())
                         .Count();
            }

            return(count);
        }
Example #6
0
        public static async Task <int> Task2(string file)
        {
            var lines = await LittleHelper.Parse(file, "\n\n", l => l);

            return(lines.Count(IsValid));
        }
Example #7
0
 private static Task <int[]> Parse(string file)
 {
     return(LittleHelper.Parse(file, "\n", int.Parse));
 }
Example #8
0
        public static async Task <int> Task1(string file)
        {
            var lines = await LittleHelper.Parse(file, "\n\n", s => s);

            return(lines.Sum(line => line.Distinct().Count(char.IsLetter)));
        }