コード例 #1
0
ファイル: Day08.cs プロジェクト: joscalv/AdventOfCode2020
        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
ファイル: Day08.cs プロジェクト: joscalv/AdventOfCode2020
 public long ExecutePart1()
 {
     Computer.Computer p = new Computer.Computer(_instructions);
     p.ExecuteStopWhenLoop();
     return(p.GetAcc());
 }