Exemplo n.º 1
0
        public string FindStartingPair(int product)
        {
            ICC icc  = new ICC(Input);
            int verb = 1;
            int max  = 99;

            int  noun  = max / 2;
            bool found = false;

            for (int i = 0; i <= 99; i++)
            {
                for (int j = 0; j <= 99; j++)
                {
                    icc.ResetMemory();
                    icc.SetArrayValues(1, i);
                    icc.SetArrayValues(2, j);
                    icc.IntCodeComputer();
                    var output = icc.opCodeSequence[0];
                    if (output == product)
                    {
                        verb  = j;
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    noun = i;
                    break;
                }
            }
            return($"{100 * noun + verb}");
        }
Exemplo n.º 2
0
        public string GetHighestThrustOutput(int phaseSettingStart, int phaseSettingEnd, bool feedbackLoop)
        {
            ICC icc = new ICC(input);

            //need to run all iterations.
            // 0 - 4.
            Int64 highestOutput = 0;
            int   max           = 4;
            int   amplifiers    = 5;
            int   comboCounter  = 0;

            //int[] outputBuff = new int[1];
            //outputBuff[0] = acs.RunAmplifier(4, 0);
            //outputBuff[0] = acs.RunAmplifier(3, outputBuff[0]);
            //outputBuff[0] = acs.RunAmplifier(2, outputBuff[0]);
            //outputBuff[0] = acs.RunAmplifier(1, outputBuff[0]);
            //outputBuff[0] = acs.RunAmplifier(0, outputBuff[0]);
            ACS[] amps = Enumerable.Range(0, 5).Select(x => new ACS(new ICC(input))).ToArray();
            for (var i = 1; i < amps.Length; i++)
            {
                amps[i].input = amps[i - 1].output;
            }

            if (feedbackLoop)
            {
                amps[0].input = amps[amps.Length - 1].output;
            }
            for (int a = phaseSettingStart; a <= phaseSettingEnd; ++a)
            {
                for (int b = phaseSettingStart; b <= phaseSettingEnd; ++b)
                {
                    for (int c = phaseSettingStart; c <= phaseSettingEnd; ++c)
                    {
                        for (int d = phaseSettingStart; d <= phaseSettingEnd; ++d)
                        {
                            for (int e = phaseSettingStart; e <= phaseSettingEnd; ++e)
                            {
                                int[] perms  = { a, b, c, d, e };
                                Int64 output = RunPhase(amps, perms, feedbackLoop);
                                if (output > highestOutput)
                                {
                                    highestOutput = output;
                                    Console.WriteLine($"New Highest Output {highestOutput}");
                                }
                                icc.ResetMemory();
                            }
                        }
                    }
                }
            }

            return(highestOutput.ToString());
        }