Beispiel #1
0
        public string Run(Aoc.Framework.Part part)
        {
            if (part == Aoc.Framework.Part.Part1)
            {
                long     count     = 0;
                string[] forbidden = new string[] { "ab", "cd", "pq", "xy" };
                foreach (string s in _input)
                {
                    int voyels = s.ToCharArray().Count(c => "aeiou".Contains(c));
                    if (voyels < 3)
                    {
                        continue;
                    }

                    char?repeated = Repetition.First(s, 2);
                    if (repeated == null)
                    {
                        continue;
                    }

                    bool wrong = false;
                    foreach (string f in forbidden)
                    {
                        if (s.Contains(f))
                        {
                            wrong = true;
                            break;
                        }
                    }
                    if (wrong)
                    {
                        continue;
                    }

                    count++;
                }

                return(count.ToString());
            }

            if (part == Aoc.Framework.Part.Part2)
            {
                long count = 0;
                foreach (string s in _input)
                {
                    if (!Repetition.Group(s, 2))
                    {
                        continue;
                    }

                    if (!Repetition.Spaced(s, 1))
                    {
                        continue;
                    }

                    count++;
                }

                return(count.ToString());
            }

            return("");
        }