public void Solve()
        {
            AsmInterpretor interpretor = new AsmInterpretor();

            interpretor.Load(this.instructions);
            interpretor.InstructionMoved += Interpretor_InstructionMoved;

            var instructions     = interpretor.Instructions;
            var instructionCount = interpretor.InstructionCount;

            for (int i = 0; i < instructionCount; i++)
            {
                if (instructions[i].OpCode != Opcode.Jmp && instructions[i].OpCode != Opcode.Nop)
                {
                    continue;
                }

                var originalInstruction = instructions[i];
                instructions[i] = originalInstruction with {
                    OpCode = instructions[i].OpCode == Opcode.Jmp ? Opcode.Nop : Opcode.Jmp
                };

                visitedInstructions = new BitArray(2048);
                if (interpretor.Execute())
                {
                    Log.Information("Loop fix detected. Accumulator is {Accumulator}", interpretor.AccumulatorValue);
                    break;
                }

                instructions[i] = originalInstruction;
            }
        }
Esempio n. 2
0
        public void Solve()
        {
            AsmInterpretor interpretor = new AsmInterpretor();

            interpretor.Load(this.instructions);
            interpretor.InstructionMoved += Interpretor_InstructionMoved;
            interpretor.Execute(0);
        }
        private void Interpretor_InstructionMoved(AsmInterpretor interpretor, int instruction)
        {
            if (visitedInstructions.Get(instruction))
            {
                interpretor.Stop();
            }

            visitedInstructions.Set(instruction, true);
        }
Esempio n. 4
0
        private void Interpretor_InstructionMoved(AsmInterpretor interpretor, int instruction)
        {
            if (visitedInstructions.Get(instruction))
            {
                Log.Information("Loop detected. Accumulator is {Accumulator}", interpretor.AccumulatorValue);
                interpretor.Stop();
            }

            visitedInstructions.Set(instruction, true);
        }