Пример #1
0
        private static PasswordsDatabase ParseInput(string input)
        {
            var database = new PasswordsDatabase();

            var entryRegex = new Regex(@"^(?<min>\d+)-(?<max>\d+) (?<policyCharacter>[a-z]): (?<password>.*)$");

            database.AddRange(from entry in input.Split(Environment.NewLine)
                              select entryRegex.Match(entry)
                              into match
                              let min                     = int.Parse(match.Groups["min"].Value)
                                                  let max = int.Parse(match.Groups["max"].Value)
                                                            let policyCharacter = match.Groups["policyCharacter"].Value[0]
                                                                                  let password = match.Groups["password"].ToString()
                                                                                                 select new PasswordPolicy(min, max, policyCharacter, password));

            return(database);
        }
Пример #2
0
 public Day2(string input)
 {
     _database = ParseInput(input);
 }