Beispiel #1
0
        public void Day02Part2_TestSolution()
        {
            long expectedOutput = 19690720;

            for (long noun = 0; noun <= 99; noun++)
            {
                for (long verb = 0; verb <= 99; verb++)
                {
                    try
                    {
                        List <long> values = DayDataUtilities.ReadMagicSmokePgmFromFile("day02.txt");

                        var sut = new MagicSmokeComputer();
                        sut.ProgramValues = values;
                        sut.Noun          = noun;
                        sut.Run();

                        if (expectedOutput == sut.ProgramValues[0])
                        {
                            Assert.Equal(6472, 100 * noun + verb);
                            return;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
            Debug.WriteLine("Done");
        }
Beispiel #2
0
        public void Day15Part1_TestSolution()
        {
            List <long> pgm = DayDataUtilities.ReadMagicSmokePgmFromFile("day15.txt");

            Assert.NotNull(pgm);
            OxyRepairDroid sut = new OxyRepairDroid(pgm);
            Point          pos = sut.FindOxygenSystem();

            Assert.Equal(0, pos.X);
            Assert.Equal(0, pos.Y);
        }
Beispiel #3
0
        public void Day11Part1_TestSoulution()
        {
            List <long> pgm = DayDataUtilities.ReadMagicSmokePgmFromFile("day11.txt");

            Assert.NotNull(pgm);
            var sut = new HullPainterRobot(pgm);

            int actual = sut.GoPaint();

            Assert.Equal(2021, actual);
        }
        public void Day09Part2_TestSolution()
        {
            List <long> pgm = DayDataUtilities.ReadMagicSmokePgmFromFile("day09.txt");

            Assert.NotNull(pgm);
            var sut = new MagicSmokeComputer(pgm);

            sut.InputPort = 2;
            sut.Run(MagicSmokeComputer.ProgramMode.Start);
            Assert.Equal(1, sut.OutputQueueSize());
            Assert.Equal(80379, sut.OutputPort());
        }
Beispiel #5
0
        public void Day02Part1_TestSolution()
        {
            List <long> values = DayDataUtilities.ReadMagicSmokePgmFromFile("day02.txt");

            Assert.Equal(137, values.Count);

            var sut = new MagicSmokeComputer();

            sut.ProgramValues = values;
            sut.Noun          = 12;
            sut.Verb          = 2;
            sut.Run();

            Assert.Equal(3716250, sut.ProgramValues[0]);
        }
        public void Day13Part1_TestSolution()
        {
            List <long> pgm = DayDataUtilities.ReadMagicSmokePgmFromFile("day13.txt");

            Assert.NotNull(pgm);

            var sut = new MagicSmokeComputer(pgm);

            MagicSmokeComputer.ProgramMode status = MagicSmokeComputer.ProgramMode.Start;
            do
            {
                status = sut.Run(status);
            } while (status != MagicSmokeComputer.ProgramMode.Stop);
            Assert.Equal(MagicSmokeComputer.ProgramMode.Stop, status);

            // analyze the out put queue
            PointEqualityComparer   peqc          = new PointEqualityComparer();
            Dictionary <Point, int> dictGameBoard = new Dictionary <Point, int>(peqc);

            do
            {
                int   x      = (int)sut.OutputPort();
                int   y      = (int)sut.OutputPort();
                int   tileId = (int)sut.OutputPort();
                Point p      = new Point(x, y);
                if (dictGameBoard.ContainsKey(p))
                {
                    dictGameBoard[p] = tileId;
                }
                else
                {
                    dictGameBoard.Add(p, tileId);
                }
            } while (sut.OutputQueueSize() > 0);
            Assert.NotEmpty(dictGameBoard);
            int blocktiles = 0;

            foreach (var tile in dictGameBoard.Values)
            {
                if (tile == 2)
                {
                    blocktiles++;
                }
            }
            //int blockedTiles = dictGameBoard.Values.Select(t => t == 2).ToList().Count();
            Assert.Equal(268, blocktiles);
        }
Beispiel #7
0
        public void Day07Part2_TestSolution()
        {
            List <long> pgm = DayDataUtilities.ReadMagicSmokePgmFromFile("day07.txt");

            Assert.NotNull(pgm);
            long minPhase  = 5;
            long maxPhase  = 9;
            long maxOutput = long.MinValue;

            for (long phaseA = minPhase; phaseA <= maxPhase; phaseA++)
            {
                for (long phaseB = minPhase; phaseB <= maxPhase; phaseB++)
                {
                    if (phaseA != phaseB)
                    {
                        for (long phaseC = minPhase; phaseC <= maxPhase; phaseC++)
                        {
                            if (phaseA != phaseC && phaseB != phaseC)
                            {
                                for (long phaseD = minPhase; phaseD <= maxPhase; phaseD++)
                                {
                                    if (phaseA != phaseD && phaseB != phaseD && phaseC != phaseD)
                                    {
                                        for (long phaseE = minPhase; phaseE <= maxPhase; phaseE++)
                                        {
                                            if (phaseA != phaseE && phaseB != phaseE && phaseC != phaseE && phaseD != phaseE)
                                            {
                                                AmplifierRig rig = new AmplifierRig(pgm);

                                                long output = rig.RunFeedbackAmpCircuit(phaseA, phaseB, phaseC, phaseD, phaseE, 0);

                                                if (output > maxOutput)
                                                {
                                                    maxOutput = output;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Assert.Equal(84088865, maxOutput);
        }
Beispiel #8
0
        public void Day11Part2_TestSoulution()
        {
            List <long> pgm = DayDataUtilities.ReadMagicSmokePgmFromFile("day11.txt");

            Assert.NotNull(pgm);
            var   sut        = new HullPainterRobot(pgm);
            Point firstWhite = new Point(0, 0);

            sut.HullDict.Add(firstWhite, 1);
            int actual = sut.GoPaint();

            Assert.Equal(249, actual);

            int maxX = sut.HullDict.Keys.Max(p => p.X);
            int minX = sut.HullDict.Keys.Min(p => p.X);
            int maxY = sut.HullDict.Keys.Max(p => p.Y);
            int minY = sut.HullDict.Keys.Min(p => p.Y);

            for (int y = maxY; y >= minY; y--)
            {
                for (int i = 0; i < 4; i++)
                {
                    for (int x = minX; x <= maxX; x++)
                    {
                        Point p = new Point(x, y);
                        if (sut.HullDict.ContainsKey(p))
                        {
                            if (sut.HullDict[p] == 1)
                            {
                                Debug.Write("....");
                            }
                            else
                            {
                                Debug.Write("####");
                            }
                        }
                        else
                        {
                            Debug.Write("####");
                        }
                    }
                    Debug.WriteLine("=");
                }
            }
            Assert.Equal(-5, minY);
        }
        public void Day05Part2_TestSolution()
        {
            List <long> values = DayDataUtilities.ReadMagicSmokePgmFromFile("day05.txt");

            Assert.Equal(223, values[values.Count - 3]);
            Assert.Equal(99, values[values.Count - 2]);
            Assert.Equal(226, values[values.Count - 1]);

            var sut = new MagicSmokeComputer();

            sut.ProgramValues = values;
            sut.InputPort     = 5;
            //sut.InputPort = 1;

            sut.Run();

            Assert.Equal(4655956, sut.OutputPort());
        }
        public void Day05Part1_TestSolution()
        {
            List <long> values = DayDataUtilities.ReadMagicSmokePgmFromFile("day05.txt");

            Assert.Equal(223, values[values.Count - 3]);
            Assert.Equal(99, values[values.Count - 2]);
            Assert.Equal(226, values[values.Count - 1]);

            var sut = new MagicSmokeComputer();

            sut.ProgramValues = values;
            sut.InputPort     = 1;

            sut.Run();
            long actualCode = 0;

            do
            {
                actualCode = sut.OutputPort();
            } while (actualCode == 0);
            Assert.Equal(14522484, actualCode);
        }
        public void Day25Part1_TestSolution()
        {
            List <long> pgm = DayDataUtilities.ReadMagicSmokePgmFromFile("day25.txt");

            Assert.NotNull(pgm);
        }
        public void Day13Part2_TestSolution()
        {
            List <long> pgm = DayDataUtilities.ReadMagicSmokePgmFromFile("day13.txt");

            Assert.NotNull(pgm);

            int   blockedTiles;
            int   val;
            var   sut    = new MagicSmokeComputer(pgm);
            Point pscore = new Point(-1, 0);
            Point ball   = null;
            Point paddle = null;
            PointEqualityComparer   peqc          = new PointEqualityComparer();
            Dictionary <Point, int> dictGameBoard = new Dictionary <Point, int>(peqc);

            sut.Coins = 2;
            MagicSmokeComputer.ProgramMode status = MagicSmokeComputer.ProgramMode.Start;
            do
            {
                status = sut.Run(status);

                // dump out the screen
                while (sut.OutputQueueSize() > 0)
                {
                    int   x      = (int)sut.OutputPort();
                    int   y      = (int)sut.OutputPort();
                    int   tileId = (int)sut.OutputPort();
                    Point p      = new Point(x, y);
                    if (dictGameBoard.ContainsKey(p))
                    {
                        dictGameBoard[p] = tileId;
                    }
                    else
                    {
                        dictGameBoard.Add(p, tileId);
                    }
                }
                // print the score
                //Console.Clear();
                //foreach (Point p in dictGameBoard.Keys)
                //{
                //    if (p.X != -1)
                //    {
                //        WriteAt(p, dictGameBoard[p]);
                //    }
                //}
                blockedTiles = 0;
                foreach (var item in dictGameBoard)
                {
                    if (item.Value == 2)
                    {
                        blockedTiles++;
                    }
                    if (item.Value == 3)
                    {
                        paddle = item.Key;
                    }
                    if (item.Value == 4)
                    {
                        ball = item.Key;
                    }
                }
                //Console.WriteLine();
                //Console.WriteLine();
                //Console.WriteLine("Score: {0}", dictGameBoard[pscore]);
                //Console.WriteLine("Tiles: {0}", blockedTiles);
                //Console.WriteLine();
                // put the input here
                if (ball.X < paddle.X)
                {
                    // left
                    val = -1;
                }
                else if (ball.X > paddle.X)
                {
                    // right
                    val = 1;
                }
                else
                {
                    val = 0;
                }
                sut.InputPort = val;
            } while (status != MagicSmokeComputer.ProgramMode.Stop);

            Assert.Equal(13989, dictGameBoard[pscore]);
        }