Esempio n. 1
0
        public override string PartOne(string input)
        {
            var rules    = ParseRules(input.Paragraphs().First());
            var expanded = new ExpandedRule(0, rules);

            var messages = input.Paragraphs()
                           .Last()
                           .ParseLines(line => line.Select(c => c == 'a' ? 2 : 118)
                                       .ToList());

            var result = messages.Count(m => expanded.MatchesMessage(m).Any(c => c == m.Count));

            return(result.ToString());
        }
Esempio n. 2
0
        public override string PartTwo(string input)
        {
            var rules = ParseRules(input.Paragraphs().First());

            var eight  = (42, -1, 42, 8, -1);
            var eleven = (42, 31, 42, 11, 31);

            rules[8]  = eight;
            rules[11] = eleven;

            var expanded = new ExpandedRule(0, rules);

            var messages = input.Paragraphs()
                           .Last()
                           .ParseLines(line => line.Select(c => c == 'a' ? 2 : 118)
                                       .ToList());

            var result = messages.Count(m => expanded.MatchesMessage(m).Any(c => c == m.Count));

            return(result.ToString());
        }