Beispiel #1
0
        public override string PartOne(string input)
        {
            var vm     = new BootCodeVM(input);
            var result = vm.Run();

            return(result.ToString());
        }
Beispiel #2
0
        public override string PartTwo(string input)
        {
            var instructions = input.ParseLines(BootCodeVM.ParseInstruction).ToList();

            for (var i = 0; i < instructions.Count; i++)
            {
                var original = instructions[i];

                if (instructions[i].instruction == "nop")
                {
                    instructions[i] = ("jmp", instructions[i].arg);
                }
                else if (instructions[i].instruction == "jmp")
                {
                    instructions[i] = ("nop", instructions[i].arg);
                }
                else
                {
                    continue;
                }

                var vm     = new BootCodeVM(instructions);
                var result = vm.Run();

                if (!vm.InfiniteLoop)
                {
                    return(result.ToString());
                }

                instructions[i] = original;
            }

            throw new Exception();
        }