public string Process(string program, int startIndex = 0)
        {
            var output = program;

            while (true)
            {
                var intList = _validator.SplitString(output).ToArray();
                var opCode  = ProgramConfiguration.GetOpCode(intList[startIndex].ToString());
                if (opCode == 99)
                {
                    return(output);
                }
                var logic = _intcodeProgramFactory.GetProgram(opCode);

                if (opCode == 4)
                {
                    _diagnosticCode = logic.Process(output, startIndex);
                }
                else if (opCode == 5 || opCode == 6)
                {
                    logic.Process(output, startIndex);
                }
                else
                {
                    output = (opCode == 3)
                        ? logic.Process(output, _systemIdentifier, startIndex)
                        : logic.Process(output, startIndex);
                }

                startIndex += logic.InstructionLength;
            }
        }
Example #2
0
 public void Should_extract_opcode_from_last_2_digits(string program, int expected)
 {
     Assert.That(ProgramConfiguration.GetOpCode(program), Is.EqualTo(expected));
 }