Exemple #1
0
        internal static int FindAccumulatorValueOnRepeat(IEnumerable <string> input)
        {
            var bootCode = new BootCode(input);

            bootCode.ExecuteUntilRepeatedInstruction();

            return(bootCode.Accumulator);
        }
Exemple #2
0
        internal static int FindAccumulatorValueAfterModification(IEnumerable <string> input)
        {
            var bootCode = new BootCode(input);

            for (var i = 0; i < bootCode.NumberOfInstructions; i++)
            {
                if (!bootCode.Modify(i))
                {
                    bootCode.Reset();
                    continue;
                }

                if (bootCode.ExecuteUntilEndOfProgram())
                {
                    return(bootCode.Accumulator);
                }

                bootCode.Reset();
            }

            throw new Exception("ohno");
        }