private static PasswordWithPolicy[] PrepareInput(List <string> listInput) { var result = new PasswordWithPolicy[listInput.Count]; for (int i = 0; i < listInput.Count; ++i) { int colonIndex = listInput[i].IndexOf(':'); int dashIndex = listInput[i].IndexOf('-'); result[i] = new PasswordWithPolicy( int.Parse(listInput[i].Substring(0, dashIndex)), int.Parse(listInput[i].Substring(dashIndex + 1, colonIndex - dashIndex - 2)), listInput[i][colonIndex - 1], listInput[i].Substring(colonIndex + 2)); } return(result); }
private static bool IsCorrect(PasswordWithPolicy policy) { int letterOccurences = 0; for (int i = 0; i < policy.password.Length; ++i) { if (policy.password[i] == policy.letter) { ++letterOccurences; if (letterOccurences > policy.num2) { return(false); } } } return(letterOccurences >= policy.num1); }
private static bool IsCorrect2(PasswordWithPolicy policy) => policy.password[policy.num1 - 1] == policy.letter ^ policy.password[policy.num2 - 1] == policy.letter;