Exemple #1
0
        public void Step1()
        {
            var inputList = _inputFiles.SplitString(_inputFiles.ReadInputFileForDay(4, false));

            var passports = new List <Passport>();

            Passport passport = null;

            foreach (var inputLine in inputList)
            {
                if (string.IsNullOrEmpty(inputLine))
                {
                    passports.Add(passport);
                    passport = null;
                    continue;
                }
                if (passport is null)
                {
                    passport = new Passport();
                }

                foreach (var inputBlock in inputLine.Split(" "))
                {
                    var inputBlockSplit = inputBlock.Split(":");
                    switch (inputBlockSplit[0])
                    {
                    case "byr": passport.BirthYear = inputBlockSplit[1];
                        break;

                    case "iyr": passport.IssueYear = inputBlockSplit[1];
                        break;

                    case "eyr": passport.ExpirationYear = inputBlockSplit[1];
                        break;

                    case "hgt": passport.Height = inputBlockSplit[1];
                        break;

                    case "hcl": passport.HairColour = inputBlockSplit[1];
                        break;

                    case "ecl": passport.EyeColour = inputBlockSplit[1];
                        break;

                    case "pid": passport.PassportID = inputBlockSplit[1];
                        break;

                    case "cid": passport.CountryID = inputBlockSplit[1];
                        break;
                    }
                }
            }
            passports.Add(passport); //End Of File...

            var validPassportCount = 0;

            foreach (var passportToValidate in passports)
            {
                if (passportToValidate.isValid(true))
                {
                    validPassportCount++;
                }
            }

            Console.WriteLine($"Day 4a result: {validPassportCount} passports valid.");
        }
Exemple #2
0
 // Count the number of valid passports (have all required feilds and those fields match some validationc criteria).
 public string PartTwo(string[] lines)
 => Passport.FromBlobsFile(lines).Count(passport => passport.HasRequiredFields && passport.HasValidFields).ToString();