public void Day19_Example_Part2_NoNewRule_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day19Part2DataExample.txt");

            Assert.Equal(47, lines.Length);

            var sut = new MonsterMessage(lines.Take(31).ToArray());

            Assert.Equal(31, sut.Rules.Count);

            var messages = lines.Skip(32).Take(14).ToArray();

            Assert.Equal(14, messages.Length);

            string exp = sut.MakeRegexForRule(0);

            int count = 0;

            foreach (var msg in messages)
            {
                var rg = Regex.Match(msg, exp);
                if (rg.Success)
                {
                    count++;
                }
            }
            Assert.Equal(3, count);
        }
        public void Day20_Example1_Part2_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day20Example1Data.txt");

            Assert.Equal(107, lines.Length);

            var sut = new JurassicJigsaw();

            sut.ReadTiles(new List <string>(lines));
            Assert.Equal(9, sut.Tiles.Count);

            do
            {
                sut.DoChanges();
                sut.ProcessEdges();
                if (sut.FindActions())
                {
                    continue;
                }
                sut.ProcessReverseMatches();
                sut.FindActions();
            } while (sut.Changes.Count > 0);
            sut.DumpEdges();
            long total = sut.FindCornerTotal();

            Assert.Equal(20899048083289, total);

            sut.MatchTiles();
            Assert.NotNull(sut.StartCorner);

            sut.DumpTileIds();
            Assert.NotNull(sut);
        }
        public void Day19_Example_WithNewRules_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day19Part2DataExample.txt");

            Assert.Equal(47, lines.Length);

            var sut = new MonsterMessage(lines.Take(31).ToArray());

            Assert.Equal(31, sut.Rules.Count);
            sut.ReplaceRule("8: 42 | 42 8");
            sut.ReplaceRule("11: 42 31 | 42 11 31");

            var messages = lines.Skip(32).Take(15).ToArray();

            Assert.Equal(15, messages.Length);

            sut.isPart2 = true;
            string exp = sut.MakeRegexForRule(0);

            int count = 0;

            foreach (var msg in messages)
            {
                var rg = Regex.Match(msg, exp);
                if (rg.Success)
                {
                    count++;
                }
            }
            Assert.Equal(12, count);
        }
Пример #4
0
        public void Day03TobaganRide_Part2_OK()
        {
            var trees = DailyDataUtilities.ReadLinesFromFile("Day03Data.txt");

            Assert.Equal(323, trees.Length);

            var forest = new ForestMap(trees);

            int numTrees   = forest.TreesOnSlope(0, 0, 1, 1);
            int totalTrees = numTrees;

            numTrees    = forest.TreesOnSlope(0, 0, 3, 1);
            totalTrees *= numTrees;

            numTrees    = forest.TreesOnSlope(0, 0, 5, 1);
            totalTrees *= numTrees;

            numTrees    = forest.TreesOnSlope(0, 0, 7, 1);
            totalTrees *= numTrees;

            numTrees    = forest.TreesOnSlope(0, 0, 1, 2);
            totalTrees *= numTrees;

            Assert.Equal(736527114, totalTrees);
        }
        public void Day20_JurassicJigsaw_Part2_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day20Data.txt");

            Assert.Equal(1727, lines.Length);

            var sut = new JurassicJigsaw();

            sut.ReadTiles(new List <string>(lines));
            Assert.Equal(144, sut.Tiles.Count);

            do
            {
                sut.DoChanges();
                sut.ProcessEdges();
                if (sut.FindActions())
                {
                    continue;
                }
                sut.ProcessReverseMatches();
                sut.FindActions();
            } while (sut.Changes.Count > 0);
            sut.DumpEdges();

            long total = sut.FindCornerTotal();

            Assert.Equal(15003787688423, total);
        }
        public void Day19_MonsterMessages_NewParts_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day19Data.txt");

            Assert.Equal(634, lines.Length);

            var sut = new MonsterMessage(lines.Take(131).ToArray());

            Assert.Equal(131, sut.Rules.Count);
            sut.ReplaceRule("8: 42 | 42 8");
            sut.ReplaceRule("11: 42 31 | 42 11 31");

            sut.isPart2 = true;
            string exp42 = sut.MakeRegexForRule(42);

            Assert.NotEmpty(exp42);
            string exp31 = sut.MakeRegexForRule(31);

            Assert.NotEmpty(exp31);

            string exp8 = sut.MakeRegexForRule(8);

            Assert.NotEmpty(exp8);
            string exp11 = sut.MakeRegexForRule(11);

            Assert.NotEmpty(exp11);
        }
        public void Day19_MonsterMessages_Part1_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day19Data.txt");

            Assert.Equal(634, lines.Length);

            var sut = new MonsterMessage(lines.Take(131).ToArray());

            Assert.Equal(131, sut.Rules.Count);

            var messages = lines.Skip(132).Take(510).ToArray();

            Assert.Equal(502, messages.Length);

            string exp = sut.MakeRegexForRule(0);

            int count = 0;

            foreach (var msg in messages)
            {
                var rg = Regex.Match(msg, exp);
                if (rg.Success)
                {
                    count++;
                }
            }
            Assert.Equal(299, count);
        }
        public void Day06ReadCustomForms_Part2_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day06Data.txt");

            var sut = new CustomFormChecker();
            int sum = sut.ProcessFormsAdvanced(lines);

            Assert.Equal(2947, sum);
        }
Пример #9
0
        public void Day04_ValidPassports_Part2_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day04Data.txt");

            var sut    = new PassportChecker();
            int actual = sut.ProcessPassports(lines, true);

            Assert.Equal(137, actual);
        }
Пример #10
0
        public void Day04_ValidPassports_TestData_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day04TestData.txt");

            var sut    = new PassportChecker();
            int actual = sut.ProcessPassports(lines, false);

            Assert.Equal(2, actual);
        }
        public void Day19_ReadData_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day19Data.txt");

            Assert.Equal(634, lines.Length);

            var sut = new MonsterMessage(lines.Take(131).ToArray());

            Assert.Equal(131, sut.Rules.Count);
        }
Пример #12
0
        public void TestTobaganRide_3R1D_OK()
        {
            var trees = DailyDataUtilities.ReadLinesFromFile("Day03TestData.txt");

            Assert.Equal(11, trees.Length);

            var forest   = new ForestMap(trees);
            int numTrees = forest.TreesOnSlope(0, 0, 3, 1);

            Assert.Equal(7, numTrees);
        }
Пример #13
0
        public void Day03ToboganForestRide_Part1_Ok()
        {
            var trees = DailyDataUtilities.ReadLinesFromFile("Day03Data.txt");

            Assert.Equal(323, trees.Length);

            var forest   = new ForestMap(trees);
            int numTrees = forest.TreesOnSlope(0, 0, 3, 1);

            Assert.Equal(167, numTrees);
        }
        public void Day06ReadCustomForms_SumEveryoneAnsweredPerGroup_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day06TestData.txt");

            Assert.Equal(15, lines.Length);

            var sut = new CustomFormChecker();
            int sum = sut.ProcessFormsAdvanced(lines);

            Assert.Equal(6, sum);
        }
Пример #15
0
        public void Day05HighestSeatId_Part1_Ok()
        {
            var boardingPasses = new List <string>();

            boardingPasses.AddRange(DailyDataUtilities.ReadLinesFromFile("Day05Data.txt"));
            Assert.Equal(814, boardingPasses.Count);
            var checker = new BoardingPassChecker();

            int maxSeatId = boardingPasses.Select(bp => checker.CalculateSeatID(bp, out int row, out int seat)).Max();

            Assert.Equal(892, maxSeatId);
        }
        public void Day07BaggageCombos_Part1_Ok()
        {
            var rules = DailyDataUtilities.ReadLinesFromFile("Day07Data.txt");

            Assert.Equal(594, rules.Length);
            var sut = new LuggageProcessor(rules);

            Assert.Equal(594, sut.BaggageRules.Count);

            var actual = sut.ComboToContainBag("shiny gold");

            Assert.Equal(151, actual);
        }
        public void Day20_JurassicJigsawPerska_Part2_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day20Data.txt");

            Assert.Equal(1727, lines.Length);

            var sut = new JurassicJigsawPerska();

            sut.Day20(new List <string>(lines));
            Assert.NotNull(sut);
            Assert.Equal(15003787688423, sut.Corners);
            Assert.Equal(1705, sut.Roughness);
        }
        public void Day20_JurassicJigsawPerska_Example_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day20Example1Data.txt");

            Assert.Equal(107, lines.Length);

            var sut = new JurassicJigsawPerska();

            sut.Day20(new List <string>(lines));
            Assert.NotNull(sut);
            Assert.Equal(20899048083289, sut.Corners);
            Assert.Equal(273, sut.Roughness);
        }
        public void Day07BaggageCount_Part2_Ok()
        {
            var rules = DailyDataUtilities.ReadLinesFromFile("Day07Data.txt");

            Assert.Equal(594, rules.Length);
            var sut = new LuggageProcessor(rules);

            Assert.Equal(594, sut.BaggageRules.Count);

            var actual = sut.TotalBagCount("shiny gold");

            Assert.Equal(41559, actual);
        }
Пример #20
0
        public void Day24_ReadDataExample1_ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day24Example1Data.Txt");

            Assert.Equal(20, lines.Length);

            var sut = new LobbyLayout();

            sut.ProcessDirections(lines);
            var actual = sut.CountBlackTiles();

            Assert.Equal(10, actual);
            Assert.Equal(15, sut.Tiles.Count);
        }
Пример #21
0
        public void GameConsole_Part1_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day08Data.txt");

            Assert.Equal(626, lines.Length);
            List <Instruction> program = lines.Select(l => new Instruction(l)).ToList();

            Assert.Equal(626, program.Count);
            var sut = new GameConsole(program);

            sut.Run();
            Assert.True(sut.Bad);
            Assert.Equal(1654, sut.Acc);
        }
Пример #22
0
        public void Day24_LobbyLayout_Part1_ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day24Data.Txt");

            Assert.Equal(471, lines.Length);

            var sut = new LobbyLayout();

            sut.ProcessDirections(lines);
            var actual = sut.CountBlackTiles();

            Assert.Equal(411, actual);
            Assert.Equal(441, sut.Tiles.Count);
        }
Пример #23
0
        public void Day22_CrabCombat_Part1_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day22Data.txt");

            Assert.Equal(53, lines.Length);

            var hand1 = lines.Skip(1).Take(25).ToArray();
            var hand2 = lines.Skip(28).Take(25).ToArray();
            var sut   = new CrabCombatGame();

            sut.Deal(hand1, hand2);
            long actual = sut.PlayMatch();

            Assert.Equal(34566, actual);
        }
Пример #24
0
        public void Day12_RainRisk_Part2_OK()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day12Data.txt");

            Assert.Equal(786, lines.Length);
            var sut = new WayPointNavigator();

            foreach (var leg in lines)
            {
                sut.Move(leg);
            }
            long actual = sut.AbsoluteDistanceTravelled();

            Assert.Equal(89936, actual);
        }
        public void Day14DockingData_Part2_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day14Data.txt");

            Assert.Equal(580, lines.Length);

            var  sut  = new DockingDataUnit();
            long lval = 0;

            foreach (var line in lines)
            {
                lval = sut.ProcessData2(line);
            }
            lval = sut.Sum();
            Assert.Equal(4195339838136, lval);
        }
Пример #26
0
        public void Day22_RecursiveCrabCombat_Part2_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day22Data.txt");

            Assert.Equal(53, lines.Length);

            var hand1 = lines.Skip(1).Take(25).ToArray();
            var hand2 = lines.Skip(28).Take(25).ToArray();
            var sut   = new RecursiveCrabCombatGame();

            sut.Deal(hand1, hand2);
            int  winner = sut.PlayMatch();
            long score  = sut.ScoreForMatch(winner);

            Assert.Equal(31854, score);
        }
        public void Day18_OperationOrder_Part1_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day18Data.txt");

            Assert.Equal(380, lines.Length);


            long sum = 0;

            foreach (var eq in lines)
            {
                var sut = new OperationOrderParser();
                sum += sut.Evaluate(eq);
            }
            Assert.Equal(8298263963837, sum);
        }
        public void Day18_OperationOrder_Part2_Ok()
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day18Data.txt");

            Assert.Equal(380, lines.Length);


            long sum = 0;

            foreach (var eq in lines)
            {
                var sut = new OperationOrderParser();
                sum += sut.Evaluate(eq, true);
            }
            Assert.Equal(145575710203332, sum);
        }
Пример #29
0
        public void Day21_AllergenAssessment_Part1_and_Part2_Ok()
        {
            var foods = DailyDataUtilities.ReadLinesFromFile("Day21Data.txt");

            Assert.Equal(35, foods.Length);

            var sut = new AllergenAssessor(foods);

            Assert.Equal(8, sut.AllergenIngredientsMap.Count);
            int actual = sut.RemoveAllergenicIngredients();

            Assert.Equal(1913, actual);

            var cdil = sut.CanonicalDangerousIngredientList();

            // wrong: gpgrb,spbxz,pfdkkzp,gtjmd,tjlz,xcfpc,txzv,znqbr
            Assert.Contains("gpgrb,tjlz,gtjmd,spbxz,pfdkkzp,xcfpc,txzv,znqbr", cdil);
        }
        public void Day19_Example_WithNewRulesSingle_Ok(string msg, bool expected)
        {
            var lines = DailyDataUtilities.ReadLinesFromFile("Day19Part2DataExample.txt");

            Assert.Equal(47, lines.Length);

            var sut = new MonsterMessage(lines.Take(31).ToArray());

            Assert.Equal(31, sut.Rules.Count);
            sut.ReplaceRule("8: 42 | 42 8");
            sut.ReplaceRule("11: 42 31 | 42 11 31");

            sut.isPart2 = true;
            string exp = sut.MakeRegexForRule(0);

            var rg = Regex.Match(msg, exp);

            Assert.Equal(expected, rg.Success);
        }