Exemple #1
0
        public static int Compute()
        {
            var input = File.ReadAllLines("inputs\\day4.txt");

            var passport = new Passport();
            var count    = 0;

            for (int i = 0; i < input.Length; i++)
            {
                if (string.IsNullOrWhiteSpace(input[i]))
                {
                    if (passport.IsValid())
                    {
                        count++;
                    }
                    passport = new Passport();
                    continue;
                }
                var properties = input[i].Split(' ');
                foreach (string prop in properties)
                {
                    var val = prop.Substring(4);
                    switch (prop.Substring(0, 3))
                    {
                    case "byr":
                        passport.BirthYear = val;
                        break;

                    case "iyr":
                        passport.IssueYear = val;
                        break;

                    case "eyr":
                        passport.ExpirationYear = val;
                        break;

                    case "hgt":
                        passport.Height = val;
                        break;

                    case "hcl":
                        passport.HairColor = val;
                        break;

                    case "ecl":
                        passport.EyeColor = val;
                        break;

                    case "pid":
                        passport.PassportId = val;
                        break;

                    case "cid":
                        passport.CountryId = val;
                        break;
                    }
                }
            }
            if (passport.IsValid())
            {
                count++;
            }
            return(count);
        }