Beispiel #1
0
        public int GetAnswer()
        {
            var allPasswords     = PasswordReader.GetAllPasswords();
            var correctPasswords = 0;

            foreach (var pass in allPasswords)
            {
                var countOfLetter = pass.Password.ToArray().Count(a => a == char.Parse(pass.Letter));
                if (countOfLetter <= pass.MaxOccurrences &&
                    countOfLetter >= pass.MinOccurrences)
                {
                    correctPasswords++;
                }
            }

            return(correctPasswords);
        }
Beispiel #2
0
        public int GetAnswer()
        {
            var allPasswords     = PasswordReader.GetAllPasswords();
            var correctPasswords = 0;

            foreach (var pass in allPasswords)
            {
                var firstPosition  = pass.Password.ToArray()[pass.MinOccurrences - 1] == char.Parse(pass.Letter);
                var secondPosition = pass.Password.ToArray()[pass.MaxOccurrences - 1] == char.Parse(pass.Letter);

                if (firstPosition ^ secondPosition)
                {
                    correctPasswords++;
                }
            }

            return(correctPasswords);
        }