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());
        }
示例#2
0
        public int Takes_input_and_saves_at_correct_location(int input, int location)
        {
            var inputSender = new QueuedInputSenderBuilder().Build();

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

            computer.Run(new[] { 3, location, 99 }); // Take an input and put the value at position 0

            return(computer.Memory.GetValueImmediate(location));
        }
        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());
        }
        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());
        }
示例#5
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);
        }