Exemplo n.º 1
0
        public static long First(List <int> list, int input)
        {
            var cpu = new OpCodeInterpreter(list.Select(x => (long)x).ToArray(), input);

            cpu.Run();
            return(cpu.LastOutput);
        }
Exemplo n.º 2
0
        public void TestMode(int testValue)
        {
            var cpu = new OpCodeInterpreter(_input, testValue);

            cpu.Run();
            Assert.Single(cpu.AllOutputs);
            _testOutputHelper.WriteLine(cpu.LastOutput.ToString());
        }
Exemplo n.º 3
0
        public void Example3()
        {
            var opcodes = new[] { 104, 1125899906842624, 99 };
            var cpu     = new OpCodeInterpreter(opcodes);

            cpu.Run();
            Assert.Equal(1125899906842624, cpu.LastOutput);
        }
Exemplo n.º 4
0
        public void Example2()
        {
            var opcodes = new[] { 1102, 34915192, 34915192, 7, 4, 7, 99, 0 };
            var cpu     = new OpCodeInterpreter(opcodes);

            cpu.Run();
            Assert.True(cpu.LastOutput > 1000000000000000); //16 digit number
        }
Exemplo n.º 5
0
        public void Example1()
        {
            var opcodes = new long[] { 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 };
            var cpu     = new OpCodeInterpreter(opcodes);

            cpu.Run();
            Assert.Equal(opcodes, cpu.AllOutputs.ToArray());
        }
Exemplo n.º 6
0
        public void Instruction_With_Jumps_Work_Correctly(int input, int expected)
        {
            var list = new List <int>()
            {
                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
            };

            var cpu = new OpCodeInterpreter(list.ToArray(), input);

            cpu.Run();
            Assert.Equal(expected, cpu.LastOutput);
        }