Exemple #1
0
        private void PuzzleOne(int parameterIndexOne, int parameterIndexTwo, bool print = false)
        {
            this.program    = new List <int>(this.input.Split(',').Select(x => int.Parse(x)));
            this.program[1] = parameterIndexOne;
            this.program[2] = parameterIndexTwo;

            for (int i = 0; i < this.program.Count; i = i + 4)
            {
                if (this.program[i] == 1)
                {
                    Intcode.OpCode1(this.program, i);
                }
                else if (this.program[i] == 2)
                {
                    Intcode.OpCode2(this.program, i);
                }
                else if (this.program[i] == 99)
                {
                    break;
                }
            }
            if (print)
            {
                Console.WriteLine("Puzzle one answer: " + this.program[0]);
            }
        }
Exemple #2
0
        private void PuzzleOne()
        {
            this.inputValue = 1;
            this.program    = new List <int>(this.input.Split(',').Select(x => int.Parse(x)));
            int programPointer = 0;

            while (true)
            {
                var instruction = ConvertIntToListReversed(this.program[programPointer]);
                int firstParameterMode = 0, secondParameterMode = 0;
                if (instruction.Count == 3)
                {
                    firstParameterMode = instruction[2];
                }
                if (instruction.Count == 4)
                {
                    firstParameterMode  = instruction[2];
                    secondParameterMode = instruction[3];
                }

                if (instruction[0] == 1)
                {
                    programPointer = Intcode.OpCode1(this.program, programPointer, firstParameterMode, secondParameterMode);
                    continue;
                }
                if (instruction[0] == 2)
                {
                    programPointer = Intcode.OpCode2(this.program, programPointer, firstParameterMode, secondParameterMode);
                    continue;
                }

                if (instruction[0] == 3)
                {
                    programPointer = Intcode.OpCode3(this.program, programPointer, firstParameterMode, this.program[programPointer + 1], this.inputValue);
                    continue;
                }
                if (instruction[0] == 4)
                {
                    programPointer = Intcode.OpCode4(this.program, programPointer, firstParameterMode, this.program[programPointer + 1]);
                    continue;
                }

                if (this.program[programPointer] == 99)
                {
                    Console.WriteLine();
                    break;
                }
            }
            Console.WriteLine();
        }