Пример #1
0
        static int TestLaunchCombinationWithFeedback(int[] sequence, int[] program)
        {
            var thrustA = new IntCode(new List <int> {
                sequence[0], 0
            }, program);

            //Console.WriteLine("Computing:");
            thrustA.Compute();
            //Console.WriteLine("thrustB:");
            var thrustB = new IntCode(new List <int> {
                sequence[1]
            }, program);

            thrustB.Compute();
            var thrustC = new IntCode(new List <int> {
                sequence[2]
            }, program);

            thrustC.Compute();
            var thrustD = new IntCode(new List <int> {
                sequence[3]
            }, program);

            thrustD.Compute();
            var thrustE = new IntCode(new List <int> {
                sequence[4]
            }, program);

            thrustE.Compute();
            var feedBack = new List <int> {
                0
            };

            do
            {
                Console.WriteLine("thrustA:");
                thrustA.ComputeWithNewInput(feedBack);
                TestOutput(thrustA.Output);
                Console.WriteLine("thrustB:");
                thrustB.ComputeWithNewInput(thrustA.Output);
                TestOutput(thrustB.Output);
                Console.WriteLine("thrustC:");
                thrustC.ComputeWithNewInput(thrustB.Output);
                TestOutput(thrustC.Output);
                Console.WriteLine("thrustD:");
                thrustD.ComputeWithNewInput(thrustC.Output);
                TestOutput(thrustD.Output);
                Console.WriteLine("thrustE:");
                thrustE.ComputeWithNewInput(thrustD.Output);
                TestOutput(thrustE.Output);
                if (thrustE != null)
                {
                    feedBack = thrustE.Output;
                }
                Console.Write("tst ");
            } while (thrustE != null);
            TestLaunchCombinationWithFeedback(thrustE.Output, sequence);
            return(thrustE.Output.Last());
        }
Пример #2
0
        //static bool IntCode(int userInput, int[] program)        {                 }
        static void Main(string[] args)
        {
            int[] input = GetData();
            //int[] input = { 3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99 };
            var computer = new IntCode(5, input);

            computer.Compute();
            //Console.WriteLine(input[0]);
        }
Пример #3
0
        static int TestLaunchCombination(int[] sequence, int[] program)
        {
            List <int> userInput;

            userInput = new List <int> {
                sequence[0], 0
            };
            var thrustA = new IntCode(userInput, program);

            thrustA.Compute();
            userInput = new List <int> {
                sequence[1], thrustA.Output.Last()
            };
            var thrustB = new IntCode(userInput, program);

            thrustB.Compute();
            userInput = new List <int> {
                sequence[2], thrustB.Output.Last()
            };
            var thrustC = new IntCode(userInput, program);

            thrustC.Compute();
            userInput = new List <int> {
                sequence[3], thrustC.Output.Last()
            };
            var thrustD = new IntCode(userInput, program);

            thrustD.Compute();
            userInput = new List <int> {
                sequence[4], thrustD.Output.Last()
            };
            var thrustE = new IntCode(userInput, program);

            thrustE.Compute();
            Console.Write(thrustE.Output.Last() + "   ");
            return(thrustE.Output.Last());
        }