Ejemplo n.º 1
0
 private void Draw(int x, int y)
 {
     computer.Reset();
     computer.ReadMemory(program);
     computer.AddInput(x);
     computer.AddInput(y);
     if (doPrint)
     {
         Console.SetCursorPosition(x, y);
     }
     computer.Run();
 }
Ejemplo n.º 2
0
        public override string Solve(string input, bool part2)
        {
            //if (part2) return "Part 2 is unavailable";
            camera.ReadMemory(input);
            camera.OnOutput += Camera_OnOutput;

            camera.InputRequested += Camera_InputRequested;
            if (part2)
            {
                camera.Memory[0] = 2;
                if (AdditionalContent != null)
                {
                    foreach (char inp in AdditionalContent.Replace("\r", ""))
                    {
                        camera.AddInput(inp);
                    }
                }
            }
            camera.Run();
            Console.SetCursorPosition(0, bottom + 1);
            if (part2)
            {
                return("DUST: " + result);
            }
            return("");
        }
Ejemplo n.º 3
0
        public override string Solve(string input, bool part2)
        {
            canvas.Add(new List <long>()
            {
                0
            });

            computer.OnOutput += OnMoveInstruction;
            computer.ReadMemory(input);
            computer.AddInput(part2 ? 1 : 0);
            computer.Run();

            int drawn = Redraw();

            Console.SetCursorPosition(0, dimensions.Y + 2);
            return(string.Format("Dimensions: {0}/{1}\r\nTiles drawn at least once: {2}\r\nPart 2 Active: {3}", dimensions.X, dimensions.Y, drawn, part2.ToString()));
        }
Ejemplo n.º 4
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.º 5
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);
        }
Ejemplo n.º 6
0
 public void AddComputerInput(int input)
 {
     computer.AddInput(input);
 }