Ejemplo n.º 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++;
            }
        }
Ejemplo n.º 2
0
 public Robot(int x, int y, string[] program)
 {
     direction = Direction.Up;
     position = new IntVector2(x, y);
     computer = new IntComputer(program);
     computer.Load();
 }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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);
        }