Exemplo n.º 1
0
 private static Day2Input StringToInput(string s)
 {
     return(RegexUtils.Deserialize <Day2Input>(s.Trim(),
                                               @"(?<RangeMin>\d+)-(?<RangeMax>\d+) (?<RequiredCharacter>.): (?<Password>.*)"));
 }
Exemplo n.º 2
0
        public static bool ValidateFields(Dictionary <string, string> passport)
        {
            var valid = true;

            try
            {
                var byr = Int32.Parse(passport["byr"]);
                if (byr < 1920 || byr > 2002)
                {
                    return(false);
                }
                var iyr = Int32.Parse(passport["iyr"]);
                if (iyr < 2010 || iyr > 2020)
                {
                    return(false);
                }
                var eyr = Int32.Parse(passport["eyr"]);
                if (eyr < 2020 || eyr > 2030)
                {
                    return(false);
                }
                var hgt    = passport["hgt"];
                var hgtInt = Int32.Parse(hgt.Substring(0, hgt.Length - 2));
                if (hgt.Contains("cm"))
                {
                    if (hgtInt < 150 || hgtInt > 193)
                    {
                        return(false);
                    }
                }
                else if (hgt.Contains("in"))
                {
                    if (hgtInt < 59 || hgtInt > 76)
                    {
                        return(false);
                    }
                }
                var hcl        = passport["hcl"];
                var hclPattern = "^[#][0-9a-f]{6}$";
                if (!RegexUtils.IsMatch(hclPattern, hcl))
                {
                    return(false);
                }
                var ecl = passport["ecl"];
                if (!RegexUtils.IsMatch("^amb|blu|brn|gry|grn|hzl|oth$", ecl))
                {
                    return(false);
                }
                var pid        = passport["pid"];
                var pidPattern = "^[0-9]{9}$";
                if (!RegexUtils.IsMatch(pidPattern, pid))
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
            return(valid);
        }
Exemplo n.º 3
0
 private static Instruction[] ConvertInput(string input)
 {
     return(RegexUtils.DeserializeMany <Instruction>(input, @"(?<Operation>\w+) (?<Argument>[+-]\d+)")
            .ToArray());
 }
Exemplo n.º 4
0
 private static List <List <MathToken> > ConvertInput(string input)
 {
     return(input.SplitIntoLines()
            .Select(line => RegexUtils.DeserializeMany <MathToken>(line, @"(?<Number>\d+)|(?<Operator>[+*()])"))
            .ToList());
 }