Exemple #1
0
            public void Puzzle_16B()
            {
                var fields    = BuildFields(PuzzleFields);
                var validator = new TrainTicketValidator
                {
                    Fields = fields
                };

                var validTickets = PuzzleNerbyTickets
                                   .Where(ticket => ticket.All(x => validator.ValidateTicketValue(x)))
                                   .ToList();

                validator.DetermineFieldOrder(validTickets);

                var departureValues = new Dictionary <string, (int index, int value)>();

                for (var i = 0; i < validator.Fields.Length; i++)
                {
                    if (validator.Fields[i].Name.StartsWith("departure"))
                    {
                        departureValues.Add(validator.Fields[i].Name, (i, PuzzleMyTicket[i]));
                    }
                }

                var departureProduct = 1L;

                foreach (var departure in departureValues)
                {
                    departureProduct *= departure.Value.value;
                }

                Assert.Equal(2355350878831, departureProduct);
            }
Exemple #2
0
            public void Example_2()
            {
                var fields = BuildFields(new[]
                {
                    "class: 0-1 or 4-19",
                    "row: 0-5 or 8-19",
                    "seat: 0-13 or 16-19"
                });
                var validator = new TrainTicketValidator
                {
                    Fields = fields
                };

                var validTickets = new[]
                {
                    new[] { 3, 9, 18 },
                    new[] { 15, 1, 5 },
                    new[] { 5, 14, 9 }
                }
                .Where(ticket => ticket.All(x => validator.ValidateTicketValue(x)))
                .ToList();

                validator.DetermineFieldOrder(validTickets);

                var expectedOrder = new[]
                {
                    "row",
                    "class",
                    "seat"
                };

                for (var i = 0; i < validator.Fields.Length; i++)
                {
                    Assert.Equal(expectedOrder[i], validator.Fields[i].Name);
                }
            }