示例#1
0
        static int IntCodeComputer(string code, int noun, int verb)
        {
            int[] intCode = code.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => int.Parse(s)).ToArray();

            intCode[1] = noun;
            intCode[2] = verb;
            bool stopRunning = false;

            for (int i = 0; i <= intCode.Length && stopRunning == false; i = i + 4)
            {
                switch (intCode[i])
                {
                case 1:
                    // Addition
                    intCode = Opcode.Calculator("addition", intCode, i + 1, i + 2, i + 3);
                    break;

                case 2:
                    // Multiplication
                    intCode = Opcode.Calculator("multiplication", intCode, i + 1, i + 2, i + 3);
                    break;

                case 99:
                    // Stop
                    stopRunning = true;
                    break;

                default:
                    // Default
                    Console.WriteLine("Default Case");
                    stopRunning = true;
                    break;
                }
            }

            return(intCode[0]);
        }