Esempio n. 1
0
        public string SolveFirstPart()
        {
            var program = dataProvider.GetData();
            var processor = new Day19Solver.Processor(program.InstructionPointer);
            while (processor.NextInstruction() < program.Instructions.Count)
            {
                var instruction = program.Instructions[processor.NextInstruction()];
                processor.Execute(instruction);
                processor.IncrementInstructionPointer();
                if (processor.NextInstruction() == 28) return processor.Registers[5].ToString();
            }

            return "";
        }
Esempio n. 2
0
        public string SolveSecondPart()
        {
            var program = dataProvider.GetData();
            var processor = new Day19Solver.Processor(program.InstructionPointer);

            var register0Stops = new List<int>();
            while (processor.NextInstruction() < program.Instructions.Count)
            {
                var instruction = program.Instructions[processor.NextInstruction()];
                processor.Execute(instruction);
                processor.IncrementInstructionPointer();
                if (processor.NextInstruction() != 28) continue;
                
                if (register0Stops.Contains(processor.Registers[5]))
                    break;
                register0Stops.Add(processor.Registers[5]);
            }
            
            return register0Stops.Last().ToString();
        }