Example #1
0
        public override void Initialize()
        {
            base.Initialize();

            computer = new IntComputer(lines);
            computer.Load();
            computer.Run();

            viewData = new Dictionary <IntVector2, int>();

            IntVector2 origin = new IntVector2(0, 0);

            while (computer.HasOutputs())
            {
                int output = (int)computer.GetOutput();

                if (output == 10)
                {
                    origin.X = 0;
                    origin.Y++;
                    continue;
                }

                viewData.Add(new IntVector2(origin.X, origin.Y), output);

                origin.X++;
            }
        }
Example #2
0
        public void SixteenDigitTest()
        {
            var computer = new IntComputer(new long[] { 1102, 34915192, 34915192, 7, 4, 7, 99 });

            computer.Run();
            Assert.AreEqual(16, computer.GetOutput().ToString().Length);
        }
Example #3
0
        public void LargeOutputTest()
        {
            const long bigNumber = 1125899906842624;
            var        computer  = new IntComputer(new long[] { 104, bigNumber, 99 });

            computer.Run();
            Assert.AreEqual(bigNumber, computer.GetOutput());
        }
        public override string GetSolution()
        {
            IntComputer computer = new IntComputer(lines);

            computer.Load();
            computer.OverrideInstruction(0, 2);

            // Figured out analog on paper
            var ascii = "A,B,B,A,B,C,A,C,B,C\n" +
                        "L,4,L,6,L,8,L,12\n" +
                        "L,8,R,12,L,12\n" +
                        "R,12,L,6,L,6,L,8\n" +
                        "n\n";

            var reversed = ascii.Select(x => (long)x);

            computer.AddInput(reversed);
            computer.Run();

            return(computer.GetOutput(computer.OutputCount() - 1).ToString());
        }
        public override void Initialize()
        {
            base.Initialize();

            pathFinder = new Pathfinder();
            IntComputer computer = new IntComputer(lines);

            computer.Load();

            direction = new IntVector2(-1, 0);
            position  = origin;

            IntVector2 rootDirection     = direction;
            int        checkedDirections = 0;

            mapData[origin] = 10;

            while (true)
            {
                IntVector2 newPosition = position + direction;

                computer.AddInput(GetMovement(direction));
                computer.Run();

                int output = (int)computer.GetOutput();

                //0: The repair droid hit a wall. Its position has not changed.
                //1: The repair droid has moved one step in the requested direction.
                //2: The repair droid has moved one step in the requested direction; its new position is the location of the oxygen system.
                switch (output)
                {
                case 0:
                    mapData[newPosition] = 1;
                    if (checkedDirections == 0)
                    {
                        direction = rootDirection;
                        checkedDirections++;
                    }
                    else if (checkedDirections == 1)
                    {
                        direction = new IntVector2(-rootDirection.Y, rootDirection.X);
                        checkedDirections++;
                    }
                    else if (checkedDirections == 2)
                    {
                        direction     = -rootDirection;
                        rootDirection = direction;
                    }
                    break;

                case 1:
                    checkedDirections    = 0;
                    rootDirection        = direction;
                    direction            = new IntVector2(rootDirection.Y, -rootDirection.X);
                    mapData[newPosition] = 0;
                    position             = newPosition;
                    break;

                case 2:
                    mapData[newPosition] = 4;
                    target   = newPosition;
                    position = newPosition;
                    break;
                }

                if (newPosition == origin)
                {
                    break;
                }
            }

            pathFinder.SetMapData(mapData);
        }
Example #6
0
 public int GetColorToPaint()
 {
     return (int)computer.GetOutput();
 }