Exemplo n.º 1
0
        public static int Run(string input)
        {
            int matches      = 0;
            var passwordSets = InputUtils.SplitLinesIntoPasswordList(input);

            foreach (var passwordSet in passwordSets)
            {
                var count = passwordSet.Password.Count(c => c == passwordSet.Letter.ToCharArray()[0]);
                if (count >= passwordSet.Min && count <= passwordSet.Max)
                {
                    matches++;
                }
            }
            return(matches);
        }
Exemplo n.º 2
0
        public static int RunPart2(string input)
        {
            int matches      = 0;
            var passwordSets = InputUtils.SplitLinesIntoPasswordList(input);

            foreach (var passwordSet in passwordSets)
            {
                var password = passwordSet.Password;
                var letter   = passwordSet.Letter;
                if ((password[passwordSet.Min - 1] == letter.ToCharArray()[0] && password[passwordSet.Max - 1] != letter.ToCharArray()[0]) ||
                    (password[passwordSet.Min - 1] != letter.ToCharArray()[0] && password[passwordSet.Max - 1] == letter.ToCharArray()[0]))
                {
                    matches++;
                }
            }
            return(matches);
        }