public string SolveSecondStar(StreamReader reader) { var rulesMap = BuildRulesMap(reader); reader.ReadLine(); var yourTicket = StringParsers.SplitDelimitedStringIntoIntList(reader.ReadLine(), ",".ToCharArray()); reader.ReadLine(); reader.ReadLine(); var line = reader.ReadLine(); var nearbyTickets = new List <List <int> >(); while (!string.IsNullOrWhiteSpace(line)) { var nearbyTicket = StringParsers.SplitDelimitedStringIntoIntList(line, ",".ToCharArray()); if (GetTicketErrorRate(nearbyTicket, rulesMap) == 0) { nearbyTickets.Add(nearbyTicket); } line = reader.ReadLine(); } var possibleIndices = GetPossibleIndices(nearbyTickets, rulesMap); var indexMap = MatchFieldsToIndices(possibleIndices); long productToReturn = 1; foreach (var field in indexMap.Keys) { if (field.StartsWith("departure")) { var indexOfDepartureField = indexMap[field]; productToReturn *= yourTicket[indexOfDepartureField]; } } return(productToReturn.ToString()); }
public string SolveFirstStar(StreamReader reader) { var rulesMap = BuildRulesMap(reader); reader.ReadLine(); var yourTicket = StringParsers.SplitDelimitedStringIntoIntList(reader.ReadLine(), ",".ToCharArray()); reader.ReadLine(); reader.ReadLine(); var line = reader.ReadLine(); long errorRate = 0; while (!string.IsNullOrWhiteSpace(line)) { var nearbyTicket = StringParsers.SplitDelimitedStringIntoIntList(line, ",".ToCharArray()); errorRate += GetTicketErrorRate(nearbyTicket, rulesMap); line = reader.ReadLine(); } return(errorRate.ToString()); }
public string SolveSecondStar(StreamReader reader) { var numbers = StringParsers.SplitDelimitedStringIntoIntList(reader.ReadLine(), ",".ToCharArray()); return(GetNthNumberSpoken(numbers, SecondStarN).ToString()); }