public static long Part2() { const string path = Helpers.inputPath + @"\day16\input.txt"; string input = ProcessInputFile(path); IList <TicketValidator.Rule> rules = ParseRules(input); TicketValidator validator = new TicketValidator(); validator.AddRules(rules); IList <int> myTicket = ParseYourTicket(input); IList <IList <int> > nearbyTickets = ParseNearbyTickets(input); IList <string> fieldOrder = FindFieldOrder(validator, nearbyTickets); long result = 1; for (int i = 0; i < myTicket.Count; i++) { if (fieldOrder[i].StartsWith("departure")) { result *= (long)myTicket[i]; } } return(result); }
//###################################################################### // Part 1 + 2 Solutions //###################################################################### public static int Part1() { const string path = Helpers.inputPath + @"\day16\input.txt"; string input = ProcessInputFile(path); IList <TicketValidator.Rule> rules = ParseRules(input); TicketValidator validator = new TicketValidator(); validator.AddRules(rules); IList <IList <int> > tickets = ParseNearbyTickets(input); int errorRate = 0; foreach (var ticket in tickets) { foreach (int val in ticket) { if (!validator.ValidateValue(val)) { errorRate += val; } } } return(errorRate); }