コード例 #1
0
    public static long[] ComputeStep(long[] memory, long startingPointer = 0)
    {
        var program  = new IntCodeProgram(memory, startingPointer);
        var compiler = new IntCodeCompiler();

        return(compiler.ComputeStep(program));
    }
コード例 #2
0
            public void Exemple4()
            {
                var input    = new long[] { 2, 4, 4, 5, 99, 0 };
                var expected = new long[] { 2, 4, 4, 5, 99, 9801 };

                TestUtility.AreEqual(expected, IntCodeCompiler.ComputeStep(input));
            }
コード例 #3
0
    public static void ConvertWhileRunning(IntCodeCompiler intCodeCompiler, IntCodeProgram program, string filename, bool useExecutorActionForMain)
    {
        string output   = "";
        int    maxSteps = 100;

        while (!program.IsDone || maxSteps-- > 0)
        {
            var instruction = program.OpCodeAtPointer;
            var opcode      = instruction % 100;
            if (opcode == 99)
            {
                output += "Halt";
                break;
            }
            else if (opcode > intCodeCompiler.Instructions.Length || intCodeCompiler.Instructions[opcode] == null)
            {
                output += $"! Missing Instruction {opcode}!\n";
                break;
            }
            else
            {
                output += InstructionToCode(program, instruction, opcode, program.Pointer);
                program = intCodeCompiler.ComputeStep(program);
            }
        }

        if (useExecutorActionForMain)
        {
            AOCExecutor.ActionForMain.Enqueue(() => AOCInput.WriteToFile(filename, output));
        }
        else
        {
            AOCInput.WriteToFile(filename, output);
        }
    }
コード例 #4
0
            public void Exemple13()
            {
                var input    = new long[] { 3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50 };
                var expected = new long[] { 3500, 9, 10, 70, 2, 3, 11, 0, 99, 30, 40, 50 };

                TestUtility.AreEqual(expected, IntCodeCompiler.ComputeStep(input, 8));
            }
コード例 #5
0
            public void Exemple3()
            {
                var input    = new long[] { 2, 3, 0, 3, 99 };
                var expected = new long[] { 2, 3, 0, 6, 99 };

                TestUtility.AreEqual(expected, IntCodeCompiler.ComputeStep(input));
            }
コード例 #6
0
            public void Part1_RelativeExample()
            {
                var compiler = new IntCodeCompiler();
                var program  = compiler.ComputeStep(new IntCodeProgram(new long[] { 109, 19 }, 0, 2000));

                Assert.AreEqual(2019, program.RelativeBaseOffset);
            }
コード例 #7
0
 public void Exemple2() => TestUtility.AreEqual(new long[] { 1101, 100, -1, 4, 99 }, IntCodeCompiler.ComputeStep(new long[] { 1101, 100, -1, 4, 0 }));
コード例 #8
0
 public void Exemple1() => TestUtility.AreEqual(new long[] { 1002, 4, 3, 4, 99 }, IntCodeCompiler.ComputeStep(new long[] { 1002, 4, 3, 4, 33 }));
コード例 #9
0
 public void MultiplyHalfImmediateHalfPosition2() => TestUtility.AreEqual(new long[] { 510, 5, 0, 0 }, IntCodeCompiler.ComputeStep(new long[] { 0102, 5, 0, 0 }));
コード例 #10
0
 public void MultiplyInImmediate3() => TestUtility.AreEqual(new long[] { -6, -1, 6, 0 }, IntCodeCompiler.ComputeStep(new long[] { 1102, -1, 6, 0 }));
コード例 #11
0
 public void AddHalfImmediateHalfPosition2() => TestUtility.AreEqual(new long[] { 106, 5, 0, 0 }, IntCodeCompiler.ComputeStep(new long[] { 0101, 5, 0, 0 }));
コード例 #12
0
 public void AddInImmediate3() => TestUtility.AreEqual(new long[] { -1, -1, 0, 0 }, IntCodeCompiler.ComputeStep(new long[] { 1101, -1, 0, 0 }));