private static bool ValidatePassportProperty(PassProperty p) { switch (p.Type) { case "byr": return(ValidateNumberRange(p.Value, 1920, 2002)); case "iyr": return(ValidateNumberRange(p.Value, 2010, 2020)); case "eyr": return(ValidateNumberRange(p.Value, 2020, 2030)); case "hgt": return(ValidateHeight(p)); case "hcl": return(RegexMatch(@"^#[0-9a-f]{6}$", p.Value)); case "pid": return(RegexMatch(@"^[0-9]{9}$", p.Value)); case "ecl": return(ValidateEyeColor(p)); default: throw new Exception($"PassProperty not implemented yet: {p}"); } }
public static List <List <PassProperty> > LoadPassports(string inputTxt, int top = 0) { var passports = File .ReadAllLines(inputTxt) .Select(s => s.Trim()) .SelectMany(r => r.Splizz(" ").ToArray()) .Aggregate(new LinkedList <List <PassProperty> >(), (passports, rawProperty) => { if (rawProperty == "" || passports.Count == 0) { passports.AddLast(new List <PassProperty>()); } var currentPassport = passports.Last.Value; if (rawProperty != "") { currentPassport.Add(PassProperty.Parse(rawProperty)); } return(passports); }); var foosList = passports.ToList(); Console.WriteLine($"Loaded {passports.Count()} entries in total ({inputTxt})"); return(foosList); }
private static bool ValidateHeight(PassProperty p) { try { var hgt = ParseHeight(p.Value); if (hgt.Unit == "cm") { return(ValidateNumberRange(hgt.Height, 150, 193)); } else if (hgt.Unit == "in") { return(ValidateNumberRange(hgt.Height, 59, 76)); } return(false); } catch { return(false); } }
private static bool ValidateEyeColor(PassProperty p) { var clrs = new string[] { "amb", "blu", "brn", "gry", "grn", "hzl", "oth" }; return(clrs.Contains(p.Value)); }