예제 #1
0
        public long ExecutePart2(Instruction[] instructions)
        {
            Computer.Computer computer = null;
            var nextInstructions       = instructions;
            int replaced = 0;

            do
            {
                computer = new Computer.Computer(nextInstructions);
                computer.ExecuteStopWhenLoop();
                nextInstructions = SwitchFirstJmpNop(instructions, replaced, out var lastReplaced);
                replaced         = lastReplaced + 1;
            } while (computer.IsFinished() != true && replaced < instructions.Length);

            return(computer?.IsFinished() == true?computer.GetAcc() : -1);
        }
예제 #2
0
 public long ExecutePart1()
 {
     Computer.Computer p = new Computer.Computer(_instructions);
     p.ExecuteStopWhenLoop();
     return(p.GetAcc());
 }