Exemplo n.º 1
0
        public int Process(int[] p_input, int p_noun, int p_verb)
        {
            int result = 0;

            p_input[1] = p_noun;
            p_input[2] = p_verb;

            for (int i = 0; i < p_input.Length; i++)
            {
                int                possibleOpCode = p_input[i];
                OpCode             opCode         = IdentifyOpCode(possibleOpCode);
                OperationParamters parameters     = new OperationParamters();

                switch (opCode)
                {
                case OpCode.ADD:
                    parameters = DetermineParameters(p_input, i);
                    ExecuteAddOperation(ref p_input, parameters);
                    i += 3;
                    break;

                case OpCode.MULTIPLY:
                    parameters = DetermineParameters(p_input, i);
                    ExecuteMultiplyOperation(ref p_input, parameters);
                    i += 3;
                    break;

                case OpCode.END:
                    result = p_input[0];
                    return(result);

                case OpCode.INVALID:
                    return(result);
                }
            }

            return(result);
        }
Exemplo n.º 2
0
 public void ExecuteAddOperation(ref int[] p_input, OperationParamters p_parameters)
 {
     p_input[p_parameters.IndexOfResult] = p_input[p_parameters.Parameter1] + p_input[p_parameters.Parameter2];
 }