Beispiel #1
0
        private static void Main()
        {
            var instructions = File.ReadAllLines("Input.txt");

            var(programOneOutput, programTwoOutput) = (new Queue <long>(), new Queue <long>());

            var runnerOne = new AssemblyRunner(instructions, programTwoOutput, programOneOutput, 0);
            var runnerTwo = new AssemblyRunner(instructions, programOneOutput, programTwoOutput, 1);

            RunTwoRunnersInParallel(runnerOne, runnerTwo);
            Console.WriteLine($"The number of values the first program sent was: {runnerOne.ValuesSent}");
        }
Beispiel #2
0
        public static void RunTwoRunnersInParallel(AssemblyRunner runnerOne, AssemblyRunner runnerTwo)
        {
            while (true)
            {
                runnerOne.ExecuteNext();
                runnerTwo.ExecuteNext();

                if (runnerOne.CurrentLine == -1 && runnerTwo.CurrentLine == -1)
                {
                    break;
                }
                if (runnerOne.Waiting && runnerTwo.Waiting)
                {
                    break;
                }
            }
        }