Example #1
0
        static (int, int) part2()
        {
            var program = CodeParser.Parse(path);
            var machine = new ExecMachine(new List <Instruction>(), endCondition);

            for (int i = 0; i < program.Count; i++)
            {
                var cloned = program.Select(i => new Instruction(i.opCode, i.param)).ToList();

                // Swap single instruction
                if (cloned[i].opCode == OpCode.JMP)
                {
                    cloned[i].opCode = OpCode.NOP;
                }
                else if (cloned[i].opCode == OpCode.NOP)
                {
                    cloned[i].opCode = OpCode.JMP;
                }

                machine.reset(cloned);
                machine.run();
                if (machine.ReachedEnd)
                {
                    return(i, machine.Accumulator);
                }
            }
            return(-1, 0);
        }
Example #2
0
        static int part1()
        {
            var program = CodeParser.Parse(path);
            var machine = new ExecMachine(program, endCondition);

            machine.run();
            return(machine.Accumulator);
        }