Пример #1
0
        internal override string SolvePart1()
        {
            ElfCPU cpu = new ElfCPU(InputLines);

            cpu.Registers[0] = 10332277;
            cpu.RunToIP(28);
            cpu.Step();
            var answer = cpu.Registers[1];

            return(answer.ToString());
        }
Пример #2
0
        internal override string SolvePart2()
        {
            ElfCPU cpu = new ElfCPU(InputLines);

            cpu.Registers[0] = 0;
            List <int> haltValues = new List <int>();
            int        haltValue;

            while (true)
            {
                cpu.RunToIP(29);
                haltValue = cpu.Registers[1];
                if (haltValues.Contains(haltValue))
                {
                    /* we've looped! */
                    break;
                }
                else
                {
                    haltValues.Add(haltValue);
                }
            }
            return(haltValues.Last().ToString());
        }