Пример #1
0
        protected override string SolvePartOne()
        {
            var rows = Input.SplitByNewline();

            var count = 0;

            foreach (var row in rows)
            {
                var toboggan = new TobogganPassword(row);

                var appearances = toboggan.Password.Count(x => x == toboggan.Letter);
                if (toboggan.FirstNumber <= appearances && appearances <= toboggan.SecondNumber)
                {
                    count++;
                }
            }

            return(count.ToString());
        }
Пример #2
0
        protected override string SolvePartTwo()
        {
            var rows = Input.SplitByNewline();

            var count = 0;

            foreach (var row in rows)
            {
                var toboggan = new TobogganPassword(row);

                var firstLetterIs  = toboggan.Password[toboggan.FirstNumber - 1] == toboggan.Letter;
                var secondLetterIs = toboggan.Password[toboggan.SecondNumber - 1] == toboggan.Letter;

                if (firstLetterIs && !secondLetterIs || !firstLetterIs && secondLetterIs)
                {
                    count++;
                }
            }

            return(count.ToString());
        }