Ejemplo n.º 1
0
        public string SolveSecondTask()
        {
            var robot    = new Robot(true);
            var computer = new OpCodeComputer.OpCodeComputer(robot, robot);

            computer.ProcessInstructions(_program);

            var xCoordinates = robot.PaintedFields.Select(x => int.Parse(x.Key.Split('_')[0]));
            var yCoordinates = robot.PaintedFields.Select(x => int.Parse(x.Key.Split('_')[1]));
            var xSize        = Math.Abs(xCoordinates.Max()) + Math.Abs(xCoordinates.Min()) + 1;
            var ySize        = Math.Abs(yCoordinates.Max()) + Math.Abs(yCoordinates.Min()) + 1;

            int minX = xCoordinates.Min(), minY = yCoordinates.Min();
            var builder = new StringBuilder();

            for (int x = 0; x < xSize; x++)
            {
                for (int y = 0; y < ySize; y++)
                {
                    var key = $"{x + minX}_{y + minY}";
                    if (robot.PaintedFields.TryGetValue(key, out bool color))
                    {
                        builder.Append(color ? '#': '.');
                    }
                }

                builder.Append(Environment.NewLine);
            }

            return(builder.ToString());
        }
Ejemplo n.º 2
0
        private string RunBoostProgram(int input)
        {
            var output   = new OutputChannel();
            var computer = new OpCodeComputer.OpCodeComputer(new InputChannel(input), output);

            computer.ProcessInstructions(_program);

            return(string.Join(',', output.Outputs));
        }
Ejemplo n.º 3
0
        public string SolveFirstTask()
        {
            var robot    = new Robot(false);
            var computer = new OpCodeComputer.OpCodeComputer(robot, robot);

            computer.ProcessInstructions(_program);

            return(robot.PaintedFields.Count.ToString());
        }
Ejemplo n.º 4
0
        public string SolveSecondTask()
        {
            var robot    = new Robot();
            var computer = new OpCodeComputer.OpCodeComputer(null, robot);

            _program[0] = 2;
            computer.ProcessInstructions(_program);

            return(string.Empty);
        }
Ejemplo n.º 5
0
        public string SolveSecondTask()
        {
            _program[0] = 2;

            var arcade   = new Arcade();
            var computer = new OpCodeComputer.OpCodeComputer(arcade, arcade);

            computer.ProcessInstructions(_program);

            return(arcade.Score.ToString());
        }
Ejemplo n.º 6
0
        public string SolveFirstTask()
        {
            var arcade   = new Arcade();
            var computer = new OpCodeComputer.OpCodeComputer(arcade, arcade);

            computer.ProcessInstructions(_program);

            return(arcade.Monitor
                   .Where(x => x.Value == TileType.Block)
                   .Count()
                   .ToString());
        }
Ejemplo n.º 7
0
        public string SolveFirstTask()
        {
            var computer = new OpCodeComputer.OpCodeComputer(_droid, _droid);

            try
            {
                computer.ProcessInstructions(_program);
            }
            catch
            { }

            return(_droid.MovesToOxygenerator.ToString());
        }
Ejemplo n.º 8
0
        public string SolveFirstTask()
        {
            Initialize();

            var phase    = 5;
            var computer = new OpCodeComputer.OpCodeComputer(
                new InputChannel(phase),
                new OutputChannel()
                );

            computer.ProcessInstructions(InputInstructions);

            return(string.Empty);
        }
Ejemplo n.º 9
0
        public string SolveFirstTask()
        {
            var robot    = new Robot();
            var computer = new OpCodeComputer.OpCodeComputer(null, robot);

            computer.ProcessInstructions(_program);

            Map = robot.GetMap();
            var intersections = GetIntersections(Map).ToList();

            ToConsoleDrawer.DrawFromDictionary(Map, ' ');

            return(intersections.Select(coor => coor.X * coor.Y).Sum().ToString());
        }
Ejemplo n.º 10
0
        private int GetOutputToThrustersWithFeedback(string phases)
        {
            var inputChannels  = new List <InputChannel>();
            var outputChannels = new List <IOutputChannel>();

            var firstInputChannel = new InputChannel();
            var max = 5;

            for (var i = 0; i < max; i++)
            {
                firstInputChannel.QueueInput(int.Parse(phases.Substring(i, 1)));
                if (i == 0)
                {
                    firstInputChannel.QueueInput(0);
                }

                var secondInputChannel = new InputChannel();
                var outputChannel      = new LinkedOutputChannel(i == max - 1 ? inputChannels[0] : secondInputChannel);

                inputChannels.Add(firstInputChannel);
                outputChannels.Add(outputChannel);

                firstInputChannel = secondInputChannel;
            }

            var tasks = new List <Task>();

            for (var j = 0; j < max; j++)
            {
                var input  = inputChannels[j];
                var output = outputChannels[j];

                var t = Task.Run(() =>
                {
                    var computer = new OpCodeComputer.OpCodeComputer(input, output);
                    computer.ProcessInstructions(Program);
                });

                tasks.Add(t);
            }

            Task.WaitAll(Task.WhenAll(tasks));

            return((int)inputChannels.First().GetNext());
        }
Ejemplo n.º 11
0
        private int GetOutputToThrusters(string phases)
        {
            var output        = new ThrusterOutput(0);
            var outputChannel = new OutputChannel(output);
            var inputChannel  = new InputChannel();
            var computer      = new OpCodeComputer.OpCodeComputer(inputChannel, outputChannel);

            for (var i = 0; i < 5; i++)
            {
                var pj = phases[i];
                inputChannel.QueueInput(int.Parse(phases.Substring(i, 1)));
                inputChannel.QueueInput(output.Value);

                computer.ProcessInstructions(Program);
            }

            return((int)output.Value);
        }