public int Solution(string input) { int validPasswords = 0; List <PasswordPolicy> passwordPolicies = passwordPolicyRepository.GetPasswordPolicies(input); foreach (PasswordPolicy passwordPolicy in passwordPolicies) { int letterOccurrences = passwordPolicy.Password.Split(passwordPolicy.Letter).Length - 1; if (letterOccurrences >= passwordPolicy.From && letterOccurrences <= passwordPolicy.To) { validPasswords++; } } return(validPasswords); }
public int Solution(string input) { int validPasswords = 0; List <PasswordPolicy> passwordPolicies = passwordPolicyRepository.GetPasswordPolicies(input); foreach (PasswordPolicy passwordPolicy in passwordPolicies) { // XOR operator (logical exclusive OR) if (passwordPolicy.Password[passwordPolicy.From - 1] == passwordPolicy.Letter ^ passwordPolicy.Password[passwordPolicy.To - 1] == passwordPolicy.Letter) { validPasswords++; } } return(validPasswords); }