Exemplo n.º 1
0
 public Day4Solution(IFileReader fileReader)
 {
     _fileReader        = fileReader;
     _passportValidator = new PassportValidator();
     InitPassports();
     ResetSolution();
 }
Exemplo n.º 2
0
        public int CheckPassports(string data, IPassportValidator validator)
        {
            var passports = SplitPassports(data);

            return(passports.Select(x => PassportData.ParsePassport(x).IsValid(validator))
                   .Count(x => x == true));
        }
Exemplo n.º 3
0
        public static void RunScan(FileInputScanner inputScanner, IPassportValidator passportValidator)
        {
            var passports = inputScanner.Scan();

            var validatedPassports =
                passports
                .Select(p => (passport: p, isValid: passportValidator.IsPassportValid(p)))
                .ToArray();

            Console.WriteLine($"Valid passports: {validatedPassports.Count(p => p.isValid)}");
            Console.WriteLine($"Invalid passports: {validatedPassports.Count(p => !p.isValid)}");
        }
Exemplo n.º 4
0
        public bool Validate()
        {
            var validators = new IPassportValidator[]
            {
                new BirthYearValidator(),
                new ExpirationYearValidator(),
                new EyeColorValidator(),
                new HairColorValidator(),
                new HeightValidator(),
                new IssueYearValidator(),
                new PassportIdValidator()
            };


            return(validators.All(validator => validator.Validate(this)));
        }
Exemplo n.º 5
0
 public PassportDay4b(string lines, IPassportValidator passportValidator) : base(lines)
 {
     this.passportValidator = passportValidator;
 }
Exemplo n.º 6
0
 public bool IsValid(IPassportValidator validator)
 {
     return(validator?.Validate(this) ?? false);
 }