예제 #1
0
        public void Day2ProgramAlarmExample3DataTest()
        {
            int[] input    = { 2, 4, 4, 5, 99, 0 };
            int[] expected = { 2, 4, 4, 5, 99, 9801 };
            var   opCalc   = new Day2ProgramAlarm();

            int[] result = opCalc.IntCodeComputer(input);
            Assert.That(result, Is.EqualTo(expected));
        }
예제 #2
0
        public void Day2ProgramAlarmExample4DataTest()
        {
            int[] input    = { 1, 1, 1, 4, 99, 5, 6, 0, 99 };
            int[] expected = { 30, 1, 1, 4, 2, 5, 6, 0, 99 };
            var   opCalc   = new Day2ProgramAlarm();

            int[] result = opCalc.IntCodeComputer(input);
            Assert.That(result, Is.EqualTo(expected));
        }
        public void ChanceOfeAsteroidsExampleOutputTest()
        {
            int[] input    = { 3, 0, 4, 0, 99 };
            int[] expected = { 25, 0, 4, 0, 99 };
            var   opCalc   = new Day2ProgramAlarm();

            int[] result = opCalc.IntCodeComputer(input, 25);
            Assert.That(result, Is.EqualTo(expected));
        }
예제 #4
0
        public void Day2ProgramAlarmExample0DataTest()
        {
            int[] input    = { 1, 9, 10, 3, 2, 3, 11, 0, 99, 30, 40, 50 };
            int[] expected = { 3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50 };
            var   opCalc   = new Day2ProgramAlarm();

            int[] result = opCalc.IntCodeComputer(input);
            Assert.That(result, Is.EqualTo(expected));
        }
        public void ChanceOfeAsteroidsExample2Test()
        {
            int[] input    = { 1101, 100, -1, 4, 0 };
            int[] expected = { 1101, 100, -1, 4, 99 };
            var   opCalc   = new Day2ProgramAlarm();

            int[] result = opCalc.IntCodeComputer(input);
            Assert.That(result, Is.EqualTo(expected));
        }
        public void Part2PositionModeIs8EqualTo8Test()
        {
            int param = 8;

            int[] input  = { 3, 9, 8, 9, 10, 9, 4, 9, 99, -1, 8 };
            var   opCalc = new Day2ProgramAlarm();

            opCalc.IntCodeComputer(input, param);
            var result = opCalc.InstructionHistory.Last(_ => _.Type == Instruction.ParamMode.Output).Noun;

            Assert.That(result, Is.EqualTo(1));
        }
        public void Part2ImmediateModeIs7LessThan8Test()
        {
            int param = 7;

            int[] input    = { 3, 3, 1107, -1, 8, 3, 4, 3, 99 };
            int   expected = 1;
            var   opCalc   = new Day2ProgramAlarm();

            opCalc.IntCodeComputer(input, param);
            var result = opCalc.InstructionHistory.Last(_ => _.Type == Instruction.ParamMode.Output).Noun;

            Assert.That(result, Is.EqualTo(expected));
        }
        public void Part2ImmediateJumpTest()
        {
            int param = 1;

            int[] input    = { 3, 3, 1105, -1, 9, 1101, 0, 0, 12, 4, 12, 99, 1 };
            int   expected = 1;
            var   opCalc   = new Day2ProgramAlarm();

            opCalc.IntCodeComputer(input, param);
            var result = opCalc.InstructionHistory.Last(_ => _.Type == Instruction.ParamMode.Output).Noun;

            Assert.That(result, Is.EqualTo(expected));
        }
        public void ChanceOfeAsteroidsRealData()
        {
            int[] input =
            {
                3,       225,     1,  225,    6,     6,  1100,     1,  238,  225,   104,     0,   101,   67,   166,  224,  1001,  224,  -110,  224,    4,  224,  102,
                8,       223,   223, 1001,  224,     4,   224,     1,  224,  223,   223,     2,    62,   66,   224,  101,  -406,  224,   224,    4,  224,  102,    8,
                223,     223,   101,    3,  224,   224,     1,   224,  223,  223,  1101,    76,    51,  225,  1101,   51,    29,  225,  1102,   57,   14,  225,
                1102,     64,    48,  224, 1001,   224, -3072,   224,    4,  224,   102,     8,   223,  223,  1001,  224,     1,  224,     1,  224,  223,  223,
                1001,    217,    90,  224, 1001,   224,  -101,   224,    4,  224,  1002,   223,     8,  223,  1001,  224,     2,  224,     1,  223,  224,
                223,    1101,    57,   55,  224,  1001,   224,  -112,  224,    4,   224,   102,     8,  223,   223, 1001,   224,    7,   224,    1,  223,  224,
                223,    1102,     5,   62,  225,  1102,    49,    68,  225,  102,    40,   140,   224,  101, -2720,  224,   224,    4,   224, 1002,  223,    8,
                223,    1001,   224,    4,  224,     1,   223,   224,  223, 1101,    92,    43,   225, 1101,    93,   21,   225, 1002,   170,   31,  224,  101,
                -651,    224,   224,    4,  224,   102,     8,   223,  223,  101,     4,   224,   224,    1,   223,  224,   223,    1,   136,   57,  224, 1001,
                224,    -138,   224,    4,  224,   102,     8,   223,  223,  101,     2,   224,   224,    1,   223,  224,   223, 1102,    11,   85,  225,    4,  223,
                99,        0,     0,    0,  677,     0,     0,     0,    0,    0,     0,     0,     0,    0,     0,    0,  1105,    0, 99999, 1105,  227,  247, 1105,1, 99999, 1005,
                227,   99999,  1005,    0,  256,  1105,     1, 99999, 1106,  227, 99999,  1106,     0,  265,  1105,    1, 99999, 1006,     0,
                99999,  1006,   227,  274, 1105,     1, 99999,  1105,    1,  280,  1105,     1, 99999,    1,   225,  225,   225, 1101,   294,    0,    0,
                105,       1,     0, 1105,    1, 99999,  1106,     0,  300, 1105,     1, 99999,     1,  225,   225,  225,  1101,  314,     0,    0,  106,    0,    0,
                1105,      1, 99999, 1107,  226,   226,   224,   102,    2,  223,   223,  1006,   224,  329,  1001,  223,     1,  223,  1007,  226,
                677,     224,  1002,  223,    2,   223,  1005,   224,  344,  101,     1,   223,   223,  108,   677,  677,   224, 1002,   223,    2,  223,
                1006,    224,   359,  101,    1,   223,   223,  1008,  226,  226,   224,  1002,   223,    2,   223, 1005,   224,  374,  1001,  223,    1,
                223,     108,   677,  226,  224,  1002,   223,     2,  223, 1006,   224,   389,   101,    1,   223,  223,     7,  226,   226,  224,  102,    2,
                223,     223,  1006,  224,  404,   101,     1,   223,  223,    7,   677,   226,   224, 1002,   223,    2,   223, 1005,   224,  419,  101,    1,
                223,     223,   107,  226,  226,   224,   102,     2,  223,  223,  1006,   224,   434, 1001,   223,    1,   223, 1008,   677,  677,  224,
                1002,    223,     2,  223, 1005,   224,   449,   101,    1,  223,   223,   108,   226,  226,   224,  102,     2,  223,   223, 1005,  224,
                464,    1001,   223,    1,  223,  1108,   226,   677,  224, 1002,   223,     2,   223, 1005,   224,  479,  1001,  223,     1,  223,    8,
                677,     226,   224,  102,    2,   223,   223,  1006,  224,  494,  1001,   223,     1,  223,  1108,  677,   677,  224,   102,    2,  223,
                223,    1006,   224,  509, 1001,   223,     1,   223, 1007,  226,   226,   224,  1002,  223,     2,  223,  1005,  224,   524, 1001,
                223,       1,   223,    7,  226,   677,   224,  1002,  223,    2,   223,  1005,   224,  539,  1001,  223,     1,  223,     8,  677,  677,  224,
                102,       2,   223,  223, 1005,   224,   554,  1001,  223,    1,   223,   107,   226,  677,   224, 1002,   223,    2,   223, 1006,  224,
                569,     101,     1,  223,  223,  1107,   226,   677,  224,  102,     2,   223,   223, 1005,   224,  584,  1001,  223,     1,  223, 1108,
                677,     226,   224,  102,    2,   223,   223,  1006,  224,  599,  1001,   223,     1,  223,  1008,  677,   226,  224,   102,    2,  223,
                223,    1006,   224,  614,  101,     1,   223,   223,  107,  677,   677,   224,   102,    2,   223,  223,  1006,  224,   629, 1001,  223,
                1,       223,  1107,  677,  226,   224,  1002,   223,    2,  223,  1005,   224,   644,  101,     1,  223,   223,    8,   226,  677,  224,  102,
                2,       223,   223, 1005,  224,   659,  1001,   223,    1,  223,  1007,   677,   677,  224,   102,    2,   223,  223,  1005,  224,  674,
                1001,    223,     1,  223,    4,   223,    99, 226
            };

            var opCalc = new Day2ProgramAlarm();

            //input[0] = 1;
            opCalc.IntCodeComputer(input, 1);
            IEnumerable <Instruction> hist = opCalc.InstructionHistory.Where(_ => _.Type == Instruction.ParamMode.Output);
            var finalOut = hist.Last();
            int forSomeReasonWeGetA3AtTheStartUnexpectedlyButTheResultIsCorrect = 3;
            int result = hist.Sum(_ => _.Noun) - forSomeReasonWeGetA3AtTheStartUnexpectedlyButTheResultIsCorrect;

            Assert.That(result, Is.EqualTo(finalOut.Noun));
            Assert.That(finalOut.Noun, Is.EqualTo(9219874));
        }
        public void Part2PositionModeJumpTest()
        {
            int param = 0;

            int[] input =
            {
                3, 12, 6, 12, 15, 1, 13, 14, 13, 4, 13, 99, -1, 0, 1, 9
            };
            int expected = 0;
            var opCalc   = new Day2ProgramAlarm();

            opCalc.IntCodeComputer(input, param);
            var result = opCalc.InstructionHistory.Last(_ => _.Type == Instruction.ParamMode.Output).Noun;

            Assert.That(result, Is.EqualTo(expected));
        }
        public void Part2PositionModeJumpTestLargerEqual()
        {
            int param = 8;

            int[] input =
            {
                3,      21, 1008, 21,    8,   20, 1005, 20,  22, 107,    8, 21,   20, 1006, 20,  31,
                1106,    0,   36, 98,    0,    0, 1002, 21, 125,  20,    4, 20, 1105,    1, 46, 104,
                999,  1105,    1, 46, 1101, 1000,    1, 20,   4,  20, 1105,  1,   46,   98, 99
            };
            int expected = 1000;
            var opCalc   = new Day2ProgramAlarm();

            opCalc.IntCodeComputer(input, param);
            var result = opCalc.InstructionHistory.Last(_ => _.Type == Instruction.ParamMode.Output).Noun;

            Assert.That(result, Is.EqualTo(expected));
        }
예제 #12
0
        public void Day2ProgramAlarmRealData()
        {
            int[] input =
            {
                1,     0,  0,   3,   1,  1,  2,   3,   1,  3,  4,   3,   1,  5,   0,   3,   2,  6,   1,  19,   1,  19,   5, 23,   2,  9, 23, 27, 1, 5, 27, 31,
                1,     5, 31,  35,   1, 35, 13,  39,   1, 39,  9,  43,   1,  5,  43,  47,   1, 47,   6,  51,   1,  51,  13, 55,   1, 55,  9, 59, 1,
                59,   13, 63,   2,  63, 13, 67,   1,  67, 10, 71,   1,  71,  6,  75,   2,  10, 75,  79,   2,  10,  79,  83,  1,   5, 83, 87,  2,
                6,    87, 91,   1,  91,  6, 95,   1,  95, 13, 99,   2,  99, 13, 103,   1, 103,  9, 107,   1,  10, 107, 111,  2, 111, 13,
                115,   1, 10, 115, 119,  1, 10, 119, 123,  2, 13, 123, 127,  2,   6, 127, 131,  1,  13, 131, 135,   1, 135,  2, 139,
                1,   139,  6,   0,  99,  2,  0,  14, 0
            };
            input[1] = 12; // noun
            input[2] = 2;  // verb
            var opCalc = new Day2ProgramAlarm();

            int[] result  = opCalc.IntCodeComputer(input);
            int   outcome = result[0];

            Assert.That(outcome, Is.EqualTo(4090689));
        }
예제 #13
0
        public void Day2ProgramAlarmRealDataWhatNounAndVerbBruteForce()
        {
            // 77 33
            int       noun = 0;
            int       verb = 0;
            Stopwatch sw   = new Stopwatch();

            sw.Start();
            bool found = false;

            for (int i = 0; i < 100; i++)
            {
                if (found)
                {
                    break;
                }
                for (int j = 0; j < 100; j++)
                {
                    int[] input =
                    {
                        1,     0,   0,   3,   1,  1,   2,  3,   1,   3,   4,  3,  1,   5,   0,  3,  2,   6,   1, 19,   1,  19,   5, 23,   2,  9, 23, 27, 1, 5,
                        27,   31,   1,   5,  31, 35,   1, 35,  13,  39,   1, 39,  9,  43,   1,  5, 43,  47,   1, 47,   6,  51,   1, 51,  13, 55,  1,
                        55,    9,  59,   1,  59, 13,  63,  2,  63,  13,  67,  1, 67,  10,  71,  1, 71,   6,  75,  2,  10,  75,  79,  2,  10, 79,
                        83,    1,   5,  83,  87,  2,   6, 87,  91,   1,  91,  6, 95,   1,  95, 13, 99,   2,  99, 13, 103,   1, 103,  9, 107,  1,
                        10,  107, 111,   2, 111, 13, 115,  1,  10, 115, 119,  1, 10, 119, 123,  2, 13, 123, 127,  2,   6, 127,
                        131,   1,  13, 131, 135,  1, 135,  2, 139,   1, 139,  6,  0,  99,   2,  0, 14, 0
                    };

                    input[1] = i; // noun
                    input[2] = j; // verb
                    var opCalc = new Day2ProgramAlarm();
                    try
                    {
                        int[] result  = opCalc.IntCodeComputer(input);
                        int   outcome = result[0];
                        if (outcome == 19690720)
                        {
                            Console.WriteLine("Found solution " + i + " " + j);
                            noun  = i;
                            verb  = j;
                            found = true;
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        // we don't care
                    }
                }
            }

            Console.WriteLine($"Done {sw.Elapsed}");

            int[] inputVerify =
            {
                1,     0,   0,   3,   1,  1,   2,  3,   1,   3,   4,  3,  1,   5,   0,  3,  2,   6,   1, 19,   1,  19,   5, 23,   2,  9, 23, 27, 1, 5,
                27,   31,   1,   5,  31, 35,   1, 35,  13,  39,   1, 39,  9,  43,   1,  5, 43,  47,   1, 47,   6,  51,   1, 51,  13, 55,  1,
                55,    9,  59,   1,  59, 13,  63,  2,  63,  13,  67,  1, 67,  10,  71,  1, 71,   6,  75,  2,  10,  75,  79,  2,  10, 79,
                83,    1,   5,  83,  87,  2,   6, 87,  91,   1,  91,  6, 95,   1,  95, 13, 99,   2,  99, 13, 103,   1, 103,  9, 107,  1,
                10,  107, 111,   2, 111, 13, 115,  1,  10, 115, 119,  1, 10, 119, 123,  2, 13, 123, 127,  2,   6, 127,
                131,   1,  13, 131, 135,  1, 135,  2, 139,   1, 139,  6,  0,  99,   2,  0, 14, 0
            };

            inputVerify[1] = noun; //77
            inputVerify[2] = verb; //33
            var verifyCalc = new Day2ProgramAlarm();

            int[] verify = verifyCalc.IntCodeComputer(inputVerify);
            Assert.That(verify[0], Is.EqualTo(19690720));
            Console.WriteLine(100 * noun + verb);
        }