示例#1
0
    private IntType[] RunProgram(IntType[] program)
    {
        var state = new Intcode.State(program);

        while (Intcode.Step(state))
        {
            // nothing
        }
        return(state.MemoryDump(program.Length));
    }
示例#2
0
    private IntType?RunProgram(ref IntType[] program, IntType input)
    {
        IntType finalOutput = -1;
        var     state       = new Intcode.State(program, input);

        while (Intcode.Step(state))
        {
            // nothing
            // consume the output
            var tempOut = state.PopOutput();
            if (tempOut.HasValue)
            {
                finalOutput = tempOut.Value;
            }
        }
        program = state.MemoryDump(program.Length);
        return(finalOutput);
    }