コード例 #1
0
        /// <summary>
        /// --- Day 8: Handheld Halting; Part B ---
        /// </summary>
        private protected override string PartB()
        {
            int acc = 0;

            string[] modifiedInput = (string[])_input.Clone();

            for (int i = 0; i < modifiedInput.Length; i++)
            {
                if (modifiedInput[i].StartsWith("jmp"))
                {
                    modifiedInput[i] = modifiedInput[i].Replace("jmp", "nop");
                }
                else if (modifiedInput[i].StartsWith("nop"))
                {
                    modifiedInput[i] = modifiedInput[i].Replace("nop", "jmp");
                }
                else
                {
                    continue;
                }

                var gameBoy = new GameBoy(modifiedInput);
                gameBoy.Boot();

                if (gameBoy.BootComplete)
                {
                    acc = gameBoy.Acc;
                    break;
                }

                modifiedInput = (string[])_input.Clone();
            }
            return(acc.ToString());
        }
コード例 #2
0
        /// <summary>
        /// --- Day 8: Handheld Halting; Part A ---
        /// </summary>
        private protected override string PartA()
        {
            var gameBoy = new GameBoy(_input);

            gameBoy.Boot();
            int acc = gameBoy.Acc;

            return(acc.ToString());
        }