示例#1
0
 public void Go()
 {
     while (!computer.IsHalted)
     {
         computer.Compute();
     }
 }
示例#2
0
        private static (int Noun, int Verb) Day2Puzzle2(string input)
        {
            var numbers = input.Split(',').Select(i => int.Parse(i)).ToArray();

            // replacements
            numbers[1] = 22;
            numbers[2] = 54;

            // 1 433 555
            // [1] * 810 000 + (1870666 + [2])
            // 19 690 720
            // 0 0 1870666
            // 0 1 1870667
            // 0 2 1870668
            // 1 0 2680666
            // 1 1 2680667
            // 1 2 2680668
            // 2 0 3490666
            // 3 0 4300666

            var intcodeComputer = new IntcodeComputer();

            numbers = intcodeComputer.Compute(numbers);
            return(22, 54);
        }
示例#3
0
        public virtual string Solve()
        {
            var data = _parser.GetData().Split(',').Select(long.Parse).ToArray();

            var input   = 1;
            var program = data.ToList();
            var amp     = new IntcodeComputer(program, input);

            amp.Compute();

            return(amp.Output.ToString());
        }
示例#4
0
        private static int Day2Puzzle1(string input)
        {
            var numbers = input.Split(',').Select(i => int.Parse(i)).ToArray();

            // replacements
            numbers[1] = 12;
            numbers[2] = 2;

            var intcodeComputer = new IntcodeComputer();

            numbers = intcodeComputer.Compute(numbers);
            return(numbers[0]);
        }
示例#5
0
        public void use_new_instructions_correctly(string input, string expected)
        {
            var programString =
                "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 volatileInstructions = programString.Split(",")
                                       .Select(long.Parse)
                                       .Select((value, index) => new KeyValuePair <long, long>(index, value));
            var ram      = new Dictionary <long, long>(volatileInstructions);
            var computer = new IntcodeComputer();

            var state = new IntcodeState
            {
                Output             = new List <string>(),
                Input              = new Queue <int>(),
                Memory             = ram,
                InstructionPointer = 0
            };

            state.Input.Enqueue(int.Parse(input));
            computer.Compute(state);

            state.Output.First().Should().Be(expected);
        }