Пример #1
0
        public void Day7TestPart2(List <long> code, List <int> phaseSequence, int expectedOutput)
        {
            var amply  = new AmplificationCircuitConfig(code, phaseSequence);
            var output = amply.ConfigureAmplifiersFeedBackLoop(0);

            Assert.IsTrue(output == expectedOutput);
        }
Пример #2
0
        /// <summary>
        /// Execution function for Day 7
        /// </summary>
        public void Execute7()
        {
            UserActionAsync(() =>
            {
                WriteToConsole("Start execution of Day7");
                var parser = GetInputParser("Day7Input.txt");
                var code   = parser.GetIntCode();

                var permu        = new PermutationNoRepetition(5, 5);
                var combinations = permu.Get(new List <int> {
                    0, 1, 2, 3, 4
                }).ToList();
                var signalOutputs = combinations.Select(phaseSettings =>
                {
                    var ampli = new AmplificationCircuitConfig(code.ToList(), phaseSettings);
                    return(ampli.ConfigureAmplifiers(0));
                }).ToList();

                var maxSignal     = signalOutputs.Max();
                var index         = signalOutputs.IndexOf(maxSignal);
                var phaseSettings = string.Join(", ", combinations[index]);

                WriteToConsole($"The best phase setting is {phaseSettings} with a signal output of {maxSignal.ToString("N")}");
                AddEmptyLine();

                WriteToConsole("Now we want to find the best pahse setting for a feedback loop configuration");
                combinations = permu.Get(new List <int> {
                    5, 6, 7, 8, 9
                }).ToList();
                signalOutputs = combinations.Select(phaseSettings =>
                {
                    var ampli = new AmplificationCircuitConfig(code.ToList(), phaseSettings);
                    return(ampli.ConfigureAmplifiersFeedBackLoop(0));
                }).ToList();

                maxSignal     = signalOutputs.Max();
                index         = signalOutputs.IndexOf(maxSignal);
                phaseSettings = string.Join(", ", combinations[index]);

                WriteToConsole($"The best phase setting for a feedback loop configuration is {phaseSettings} with a signal output of {maxSignal.ToString("N")}");
                AddEmptyLine();
            });
        }