Exemple #1
0
        private int TestInputs(int noun, int verb)
        {
            List <int> computerMemory = new List <int>(ComputerMemory);

            computerMemory[1] = noun;
            computerMemory[2] = verb;

            var skip = 0;

            while (true)
            {
                var intCode       = computerMemory.Skip(skip).Take(opCodeLength).ToArray();
                var currentOpcode = new IntCode()
                {
                    InstructionID = intCode[0], fromPosition1 = intCode[1], fromPosition2 = intCode[2], toPosition = intCode[3]
                };
                if (currentOpcode.Terminate)
                {
                    break;
                }
                currentOpcode.valuefromPosition1 = computerMemory[currentOpcode.fromPosition1];
                currentOpcode.valuefromPosition2 = computerMemory[currentOpcode.fromPosition2];
                currentOpcode.ExecuteOperation();
                computerMemory[currentOpcode.toPosition] = currentOpcode.toPositionResult;
                skip += opCodeLength;
            }
            ;
            return(computerMemory[0]);
        }