Example #1
0
        public void Test_DayFive_PartOne()
        {
            var fn = Path.Combine(TestHelper.TestDir, "Day5.Input.txt");

            try
            {
                //< Generate and run the Intcode
                var intcode = new Core.Classes.Intcode(fn);
                intcode.AddInput(1);
                intcode.Process();

                //< Need to validate that all outputs save the last were 0
                var countNonZero = intcode.Outputs.Count(output => output.Item2 != 0);
                Assert.IsTrue(countNonZero == 1);

                //< Need to ensure the non-zero output is the last, and that it's the correct value (6761139)
                var nonZero    = intcode.Outputs.Where(o => o.Item2 != 0).Single();
                var idxNonZero = intcode.Outputs.IndexOf(nonZero);
                Assert.IsTrue(idxNonZero == intcode.Outputs.Count - 1);
                Assert.IsTrue(nonZero.Item2 == 6761139);
            }
            catch (Exception e)
            {
                //< Rip
                int fail = 1;
            }
        }
Example #2
0
        public void Test_KnownResults()
        {
            var prog0 = "109,19,204,-34,99";
            var prog1 = "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99";
            var prog2 = "1102,34915192,34915192,7,4,7,99,0";
            var prog3 = "104,1125899906842624,99";

            var int0 = new Core.Classes.Intcode(prog0);

            int0.SetRelativeBase(2000);
            int0.SetValue(1985, 1985);
            int0.Process();
            Assert.IsTrue(int0.Outputs.Single().Item2 == 1985);

            var int1 = new Core.Classes.Intcode(prog1);

            int1.Process();
            var resArr = string.Join(",", int1.Outputs.Select(o => o.Item2));

            Assert.IsTrue(resArr.Equals(prog1));

            var int2 = new Core.Classes.Intcode(prog2);

            int2.Process();
            Assert.IsTrue(int2.Outputs.Single().Item2 == 1219070632396864);

            var int3 = new Core.Classes.Intcode(prog3);

            int3.Process();
            Assert.IsTrue(int3.Outputs.Single().Item2 == 1125899906842624);
        }
Example #3
0
        public void Test_Opcodes()
        {
            foreach (var testTup in _TestTups)
            {
                var intcode = new Core.Classes.Intcode(testTup.Item1);
                intcode.Process();

                Assert.IsTrue(intcode.Source.SequenceEqual(testTup.Item2));
            }
        }
Example #4
0
        public void Test_KnownComparisons()
        {
            foreach (var testTup in ComparisonTests)
            {
                var intcode = new Core.Classes.Intcode(testTup.Item2);
                intcode.AddInput(testTup.Item1);
                intcode.Process();

                Assert.IsTrue(intcode.Outputs.Single().Item2 == testTup.Item3);
            }
        }
Example #5
0
        public void Test_DayTwo_PartTwo()
        {
            //< This one has the un-altered input
            var fn = Path.Combine(TestHelper.TestDir, "Day2.Input - Backup.txt");

            const int nounPos  = 1;
            const int verbPos  = 2;
            const int finalVal = 19690720;

            int final_verb = -1;
            int final_noun = -1;

            try
            {
                //< We need to batch run every possibility of inputs as pos 1 / 2 between [0, 99] and find what pair results in '19690720'
                for (int noun = 0; noun < 100; noun++)
                {
                    if (final_noun != -1 && final_noun != -1)
                    {
                        break;
                    }

                    for (int verb = 0; verb < 100; verb++)
                    {
                        //< Ensure we ain't done
                        if (final_noun != -1 && final_noun != -1)
                        {
                            break;
                        }

                        //< Instantiate the Intcode
                        var intcode = new Core.Classes.Intcode(fn);
                        //< Alter the verb and noun and run
                        intcode.SetValue(nounPos, noun);
                        intcode.SetValue(verbPos, verb);
                        intcode.Process();
                        //< Check the value
                        if (intcode.GetValue(0) == finalVal)
                        {
                            final_verb = verb;
                            final_noun = noun;
                        }
                    }
                }
                //< Final noun is 82 and final verb is 50
                Assert.IsTrue(final_verb == 50 && final_noun == 82);
            }
            catch (Exception e)
            {
                //< Rip
                int fail = 1;
            }
        }
Example #6
0
        public void Test_DayNine_PartTwo()
        {
            var input   = Path.Combine(TestHelper.TestDir, "Day9.Input.txt");
            var intcode = new Core.Classes.Intcode(input);

            //< The input is now '2'
            intcode.AddInput(2);
            intcode.Process();

            //< Should only be one output as no Opcodes are failing
            Assert.IsTrue(intcode.Outputs.Count == 1);
            //< The resulting BOOST keycode should be '47253'
            Assert.IsTrue(intcode.Outputs.Single().Item2 == 47253);
        }
Example #7
0
        public void Test_DayTwo_PartOne()
        {
            var fn = Path.Combine(TestHelper.TestDir, "Day2.Input.txt");

            try
            {
                //< Generate and run the Intcode
                var intcode = new Core.Classes.Intcode(fn);
                intcode.Process();

                //< Ensure we've got the right first result
                Assert.IsTrue(intcode.Source[0] == 3562672);
            }
            catch (Exception e)
            {
                //< Rip
                int fail = 1;
            }
        }
Example #8
0
        public void Test_DayFive_PartTwo()
        {
            var fn = Path.Combine(TestHelper.TestDir, "Day5.Input.txt");

            try
            {
                //< Generate and run the Intcode
                var intcode = new Core.Classes.Intcode(fn);
                intcode.AddInput(5);
                intcode.Process();

                //< There should only be one output
                var output = intcode.Outputs.Single();
                Assert.IsTrue(output.Item2 == 9217546);
            }
            catch (Exception e)
            {
                //< Rip
                int fail = 1;
            }
        }