public int Jump_if_false(int[] instructions)
        {
            var output   = new QueuedOutputReceiverBuilder().Build();
            var computer = new IntcodeComputerBuilder().WithOutputReceiver(output).Build();

            computer.Run(instructions);

            return(output.Dequeue());
        }
        public int Jump_tests_examples(int[] instructions, int input)
        {
            var outputReceiver = new QueuedOutputReceiverBuilder().Build();
            var inputSender    = new QueuedInputSenderBuilder().WithQueuedValues(input).Build();
            var computer       = new IntcodeComputerBuilder().WithOutputReceiver(outputReceiver).WithInputSender(inputSender).Build();

            computer.Run(instructions);

            return(outputReceiver.Dequeue());
        }
Exemplo n.º 3
0
        public int Returns_output_defined_by_program(int location)
        {
            IOutputReceiver outputReceiver = new QueuedOutputReceiverBuilder().Build();
            var             computer       = new IntcodeComputerBuilder().WithOutputReceiver(outputReceiver).Build();

            computer.Run(new[] { 4, location, 99, 50, 60 });

            var result = outputReceiver.Dequeue();

            Assert.IsTrue(outputReceiver.IsEmpty());

            return(result);
        }
Exemplo n.º 4
0
        public void Puzzle5_day2_answer()
        {
            var code           = File.ReadLines("C:\\Code\\github\\AdventOfCode2019\\Puzzle5\\input.txt").First();
            var interpreter    = new InterpreterBuilder().Build();
            var instructions   = interpreter.Interpret(code);
            var inputSender    = new QueuedInputSenderBuilder().Build();
            var outputReceiver = new QueuedOutputReceiverBuilder().ThatIgnoresZeros().Build();
            var computer       = new IntcodeComputerBuilder().WithInputSender(inputSender).WithOutputReceiver(outputReceiver).Build();

            inputSender.Enqueue(5);
            computer.Run(instructions);

            Assert.AreEqual(9217546, outputReceiver.Dequeue());
        }
Exemplo n.º 5
0
        public void Puzzle5_day1_answer()
        {
            var code           = File.ReadLines(@"C:\Users\Neil\Documents\GitHub\AdventOfCode2019\Puzzle5\input.txt").First();
            var interpreter    = new InterpreterBuilder().Build();
            var instructions   = interpreter.Interpret(code);
            var inputSender    = new QueuedInputSenderBuilder().Build();
            var outputReceiver = new QueuedOutputReceiverBuilder().ThatIgnoresZeros().Build();
            var computer       = new IntcodeComputerBuilder().WithInputSender(inputSender).WithOutputReceiver(outputReceiver).Build();

            inputSender.Enqueue(1);
            computer.Run(instructions);

            Assert.AreEqual(6761139, outputReceiver.Dequeue());
        }
Exemplo n.º 6
0
        public int Outputs_whatever_was_input(int[] instructions, int input)
        {
            var inputSender = new QueuedInputSenderBuilder().Build();

            inputSender.Enqueue(input);
            var outputReceiver = new QueuedOutputReceiverBuilder().Build();
            var computer       =
                new IntcodeComputerBuilder()
                .WithInputSender(inputSender)
                .WithOutputReceiver(outputReceiver)
                .Build();

            computer.Run(instructions);

            var result = outputReceiver.Dequeue();

            Assert.IsTrue(outputReceiver.IsEmpty());

            return(result);
        }