예제 #1
0
        // delegate i/o
        public IntCode(string instanceName, long[] code, IntCodeInput inputDelegate, IntCodeOutput outputDelegate)
        {
            SetCode(instanceName, code);

            InputDelegate  = inputDelegate;
            OutputDelegate = outputDelegate;
        }
예제 #2
0
        private static long RunPhasePermutationWithFeedback(string program, IList <int> phases)
        {
            phases = phases.ToList();
            var outputs = new List <long?>();
            var outputE = new IntCodeOutput {
                Output = 0
            };

            var amplifierA = new IntCodeComputer(program, phases[0]);
            var amplifierB = new IntCodeComputer(program, phases[1]);
            var amplifierC = new IntCodeComputer(program, phases[2]);
            var amplifierD = new IntCodeComputer(program, phases[3]);
            var amplifierE = new IntCodeComputer(program, phases[4]);

            while (true)
            {
                var outputA = amplifierA.NextOutput(outputE.Output);
                var outputB = amplifierB.NextOutput(outputA.Output);
                var outputC = amplifierC.NextOutput(outputB.Output);
                var outputD = amplifierD.NextOutput(outputC.Output);
                outputE = amplifierE.NextOutput(outputD.Output);

                outputs.Add(outputE.Output);
                if (outputE.IsComplete)
                {
                    return(outputs.Where(o => o != null).Select(o => o.Value).Max());
                }
            }
        }
예제 #3
0
        // delegate i/o
        public IntCode(string instanceName, long[] code, IntCodeInput inputDelegate, IntCodeOutput outputDelegate)
        {
            InstanceName = instanceName;

            Code = new long[code.Length * 10]; // extra space at end
            code.CopyTo(Code, 0);

            InputDelegate  = inputDelegate;
            OutputDelegate = outputDelegate;
        }
예제 #4
0
 public void SetNewOutputDelegate(IntCodeOutput outputDelegate)
 {
     OutputDelegate = outputDelegate;
 }