示例#1
0
        public string ExecutePart1(string input)
        {
            var comp = new OpCodeComp(input.ToLines());

            comp.RunProgram();
            return(comp.AccRegister.ToString());
        }
示例#2
0
        public string ExecutePart2(string input)
        {
            var comp = new OpCodeComp(input.ToLines());

            var instuctionsToChange = comp.Memory.Where(x => x.Instruction == Instruction.Jmp || x.Instruction == Instruction.Nop);

            foreach (var item in instuctionsToChange)
            {
                item.Instruction = item.Instruction == Instruction.Nop ? Instruction.Jmp : Instruction.Nop;
                comp.RunProgram();
                if (comp.End)
                {
                    break;
                }

                item.Instruction = item.Instruction == Instruction.Nop ? Instruction.Jmp : Instruction.Nop;
            }

            return(comp.AccRegister.ToString());
        }