Beispiel #1
0
        public void Part2()
        {
            var ticketValidator = new TicketTranslator(_input);
            var fieldMaps       = ticketValidator.GetFieldMap();
            var myTicket        = ticketValidator.MyTicket;

            var answer = fieldMaps
                         .Where(fm => fm.FieldName.StartsWith("departure"))
                         .Aggregate(1L, (l, fieldMap) => l * myTicket.Values[fieldMap.FieldIndex]);

            TestContext.WriteLine($"Answer = {answer}");
        }
Beispiel #2
0
        public void Part2WithTestData()
        {
            var ticketValidator = new TicketTranslator(_testData2);
            var fieldMaps       = ticketValidator.GetFieldMap().ToList();
            var myTicket        = ticketValidator.MyTicket;

            int GetTicketValue(string fieldName)
            {
                return(myTicket.Values[fieldMaps.Single(fm => fm.FieldName == fieldName).FieldIndex]);
            }

            GetTicketValue("class").ShouldBe(12);
            GetTicketValue("row").ShouldBe(11);
            GetTicketValue("seat").ShouldBe(13);
        }