Пример #1
0
        public override string A()
        {
            IntcodeComputer brain  = new IntcodeComputer(Input);
            int             blocks = 0;
            int             index  = 1;

            brain.OnOutput += val => {
                if (index++ % 3 == 0 && val == 2)
                {
                    blocks++;
                }
            };
            brain.Start();
            return(blocks.ToString());
        }
Пример #2
0
        public override string A()
        {
            long biggest = 0;

            foreach (int[] phases in GetPermutations(new[] { 0, 1, 2, 3, 4 }))
            {
                long input = 0;
                foreach (int phase in phases)
                {
                    input = IntcodeComputer.Run(Input, phase, input);
                }
                if (input > biggest)
                {
                    biggest = input;
                }
            }
            return(biggest.ToString());
        }
Пример #3
0
        public override string B()
        {
            long score = 0;

            long[] program = Input.Split(",").Select(long.Parse).ToArray();
            program[0] = 2;
            IntcodeComputer brain = new IntcodeComputer(program);

            long ball   = 0;
            long paddle = 0;
            int  index  = 0;
            long lastX  = 0;

            brain.OnOutput += val => {
                index++;
                if (index == 1)
                {
                    lastX = val;
                }
                else if (index == 3)
                {
                    index = 0;
                    if (lastX == -1)
                    {
                        score = val;
                    }
                    else if (val == 3)
                    {
                        paddle = lastX;
                    }
                    else if (val == 4)
                    {
                        ball = lastX;
                    }
                }
            };

            brain.WantsInput += () => paddle <ball ? 1 : paddle> ball ? -1 : 0;

            brain.Start();
            return(score.ToString());
        }
Пример #4
0
        public override string B()
        {
            long[] originalProgram = Input.Split(",").Select(long.Parse).ToArray();
            long   target          = 19690720;
            long   a        = 12;
            long   previous = 0;
            long   result   = 0;

            while (result < target)
            {
                previous = result;
                long[] program = (long[])originalProgram.Clone();
                program[1] = ++a;
                program[2] = 0;
                IntcodeComputer.Run(ref program);
                result = program[0];
            }
            long b = target - previous;

            return((((a - 1) * 100) + b).ToString());
        }