示例#1
0
        public void Day16ParseTestData_Example2_OK()
        {
            var lines = new List <string>(testLines2);

            Assert.Equal(11, lines.Count);

            var rules    = lines.Take(3).ToList();
            var myTicket = lines[5];
            var tickets  = lines.Skip(8).Take(3).ToList();

            Assert.StartsWith("seat:", rules[2]);
            Assert.False(string.IsNullOrWhiteSpace(myTicket));

            var sut = new TicketScanner();

            sut.ParseClassRules(rules.ToArray());
            Assert.Equal(3, sut.ClassRules.Count);

            var result = sut.ValidateTickets(tickets);

            Assert.Equal(0, result.Count);
            Assert.Equal(0, result.Sum());
            Assert.Equal(3, sut.ValidTickets.Count);
            sut.ExpandTickets();
            Assert.Equal(3, sut.ValidTicketColumns.Count);

            sut.MatchRulesToColumns();
            Assert.Equal(3, sut.RuleToColumnMatches.Count);
        }
示例#2
0
        public void Day16ParseData_Part2_OK()
        {
            var lines = new List <string>(DailyDataUtilities.ReadLinesFromFile("Day16Data.txt"));

            Assert.Equal(266, lines.Count);

            var rules    = lines.Take(20).ToList();
            var myTicket = lines[22];
            var tickets  = lines.Skip(25).Take(241).ToList();

            Assert.StartsWith("zone:", rules[19]);
            Assert.False(string.IsNullOrWhiteSpace(myTicket));

            var sut = new TicketScanner();

            sut.ParseClassRules(rules.ToArray());
            Assert.Equal(20, sut.ClassRules.Count);

            var result = sut.ValidateTickets(tickets);

            Assert.Equal(20091, result.Sum());

            Assert.Equal(190, sut.ValidTickets.Count);
            sut.ExpandTickets();
            sut.MatchRulesToColumns();
            Assert.Equal(20, sut.RuleToColumnMatches.Count);

            sut.MakeUniqueRuleToColumnMatch();
            var  indices  = sut.ListDepartureColumns();
            var  myfields = myTicket.Split(new char[] { ',' }).Select(p => long.Parse(p)).ToList();
            long actual   = 1;

            foreach (var idx in indices)
            {
                actual *= myfields[idx];
            }
            Assert.Equal(2325343130651, actual);
        }
示例#3
0
        public void Day16ParseData_Part1_OK()
        {
            var lines = new List <string>(DailyDataUtilities.ReadLinesFromFile("Day16Data.txt"));

            Assert.Equal(266, lines.Count);

            var rules    = lines.Take(20).ToList();
            var myTicket = lines[22];
            var tickets  = lines.Skip(25).Take(241).ToList();

            Assert.StartsWith("zone:", rules[19]);
            Assert.False(string.IsNullOrWhiteSpace(myTicket));

            var sut = new TicketScanner();

            sut.ParseClassRules(rules.ToArray());
            Assert.Equal(20, sut.ClassRules.Count);

            var result = sut.ValidateTickets(tickets);

            Assert.Equal(20091, result.Sum());

            Assert.Equal(190, sut.ValidTickets.Count);
        }