Ejemplo n.º 1
0
        static int CheckBeam(int x, int y)
        {
            var lines = Utilities.GetStringFromFile("Day19.txt").SplitLongArrayFromString(',');

            var vm = new IntCodeVM(new IntCodeVMConfiguration()
            {
            });

            vm.WriteProgram(lines);
            while (vm.RunProgram() == HALTTYPE.HALT_WAITING)
            {
                vm.WriteInput(x);
                vm.WriteInput(y);
            }

            return((int)vm.outputs.Dequeue());
        }
Ejemplo n.º 2
0
        static void P2()
        {
            var lines = Utilities.GetStringFromFile("Day13.txt").SplitLongArrayFromString(',');

            var vm = new IntCodeVM(new IntCodeVMConfiguration()
            {
            });

            vm.WriteProgram(lines);
            vm.WriteMemory(0, 2);
            processOutputs(vm);
            //Draw(grid);

            while (vm.RunProgram() == HALTTYPE.HALT_WAITING)
            {
                processOutputs(vm);

                if (ballPos < paddlepos)
                {
                    vm.WriteInput(-1);
                }
                else if (ballPos > paddlepos)
                {
                    vm.WriteInput(1);
                }
                else
                {
                    vm.WriteInput(0);
                }
                Draw(grid);

                if (blockcount == 0)
                {
                    break;
                }
            }
            processOutputs(vm);
            Draw(grid);
        }
Ejemplo n.º 3
0
        public static void P2()
        {
            var lines = Utilities.GetStringFromFile("Day17.txt").SplitLongArrayFromString(',');

            var vm = new IntCodeVM(new IntCodeVMConfiguration()
            {
                FriendlyLogging = false
            });

            vm.WriteProgram(lines);
            vm.WriteMemory(0, 2);

            var input = "65,44,65,44,66,44,67,44,66,44,67,44,66,44,67,44,67,44,65,10,76,44,49,48,44,82,44,56,44,82,44,56,10,76,44,49,48,44,76,44,49,50,44,82,44,56,44,82,44,49,48,10,82,49,48,44,76,49,50,44,82,49,48,10".Split(",").Select(int.Parse).ToList();
            var main  = "65,44,65,44,66,44,67,44,66,44,67,44,66,44,67,44,67,44,65,10".Split(",").Select(int.Parse).ToList();
            var A     = "76,44,49,48,44,82,44,56,44,82,44,56,10".Split(",").Select(int.Parse).ToList();
            var B     = "76,44,49,48,44,76,44,49,50,44,82,44,56,44,82,44,49,48,10".Split(",").Select(int.Parse).ToList();
            var C     = "82,44,49,48,44,76,44,49,50,44,82,44,49,48,10".Split(",").Select(int.Parse).ToList();
            //foreach (var inp in input)
            //{
            //    vm.WriteInput(inp);
            //}
            //vm.WriteInput(110);
            //vm.WriteInput(10);

            var inpPhase = 0;

            while (vm.RunProgram() == HALTTYPE.HALT_WAITING)
            {
                while (vm.outputs.Count > 0)
                {
                    Console.Write((char)vm.outputs.Dequeue());
                }
                switch (inpPhase)
                {
                case 0:
                    foreach (var inp in main)
                    {
                        vm.WriteInput(inp);
                    }
                    inpPhase++;
                    break;

                case 1:
                    foreach (var inp in A)
                    {
                        vm.WriteInput(inp);
                    }
                    inpPhase++;
                    break;

                case 2:
                    foreach (var inp in B)
                    {
                        vm.WriteInput(inp);
                    }
                    inpPhase++;
                    break;

                case 3:
                    foreach (var inp in C)
                    {
                        vm.WriteInput(inp);
                    }
                    inpPhase++;
                    break;

                case 4:
                    vm.WriteInput((int)'Y');
                    vm.WriteInput(10);
                    inpPhase++;
                    break;
                }
            }

            var x = vm.outputs.First();
            var y = vm.outputs.Last();
            int e = 0;
            var s = "";

            while (vm.outputs.Count > 0)
            {
                s += (char)vm.outputs.Dequeue();
                e++;
                if (e == 2051)
                {
                    Console.Clear();
                    Console.WriteLine(s);
                    s = "";
                    e = 0;
                    Thread.Sleep(250);
                }
            }

            while (vm.RunProgram() == HALTTYPE.HALT_WAITING)
            {
            }
        }
Ejemplo n.º 4
0
        static void P1()
        {
            var lines = Utilities.GetStringFromFile("Day15.txt").SplitLongArrayFromString(',');

            var vm = new IntCodeVM(new IntCodeVMConfiguration()
            {
            });

            vm.WriteProgram(lines);
            grid[25, 25] = 'S';

            Draw(grid);



            vm.WriteInput((long)Facing.north);

            //vm.WriteMemory(0, 1);
            while (vm.RunProgram() == HALTTYPE.HALT_WAITING)
            {
                processOutputs(vm);

                if (complete)
                {
                    break;
                }

                //what type of step was taken?
                switch (stepType)
                {
                case StepType.forward:
                    //was step forward successful?  if not turn left
                    if (!stepSuccess)
                    {
                        TurnDirection(Direction.left);
                    }
                    //attempt to turn right now.
                    stepType = StepType.right;
                    vm.WriteInput((long)GetTurnDirection(Direction.right));
                    break;

                case StepType.right:
                    //if step was successful change facing and try to turn right again
                    if (stepSuccess)
                    {
                        TurnDirection(Direction.right);
                        stepType = StepType.right;
                        vm.WriteInput((long)GetTurnDirection(Direction.right));
                    }
                    //step unsuccessful, continue forward.
                    else
                    {
                        vm.WriteInput((long)currentFacing);
                        stepType = StepType.forward;
                    }
                    break;

                default:
                    break;
                }

                //Draw(grid);
            }

            Draw(grid);

            int[] target = new int[] { 0, 0 };

            for (int i = 0; i < grid.GetLength(0); i++)
            {
                for (int j = 0; j < grid.GetLength(1); j++)
                {
                    if (grid[i, j] == 'O')
                    {
                        target = new int[] { i, j };
                    }
                }
            }

            var s = new seeker(target, 0, grid, new int[] { 25, 25 }, Facing.north);

            var result = s.Seek();

            Console.WriteLine($"Min Steps to get to Oxygen Control: {result.Value}");
        }
Ejemplo n.º 5
0
        static void P1()
        {
            var lines = Utilities.GetStringFromFile("Day19.txt").SplitLongArrayFromString(',');



            char[,] charmap = new char[1200, 1200];

            Queue <KeyValuePair <int, int> > coords = new Queue <KeyValuePair <int, int> >();

            Queue <KeyValuePair <int, int> > usedcoords = new Queue <KeyValuePair <int, int> >();

            for (int i = 0; i < 1200; i++)
            {
                for (int j = 0; j < 1200; j++)
                {
                    coords.Enqueue(new KeyValuePair <int, int>(i, j));
                }
            }
            Queue <long> outputs = new Queue <long>();

            while (coords.Count > 0)
            {
                Console.WriteLine(coords.Count);
                var vm = new IntCodeVM(new IntCodeVMConfiguration()
                {
                });
                vm.WriteProgram(lines);
                var coord = coords.Dequeue();
                vm.WriteInput(coord.Key);
                vm.WriteInput(coord.Value);

                while (vm.RunProgram() == HALTTYPE.HALT_WAITING)
                {
                    if (coords.Count == 0)
                    {
                        break;
                    }
                }
                outputs.Enqueue(vm.outputs.Dequeue());
                usedcoords.Enqueue(new KeyValuePair <int, int>(coord.Key, coord.Value));
            }



            long count = 0;

            while (outputs.Count > 0)
            {
                var output   = outputs.Dequeue();
                var outcoord = usedcoords.Dequeue();
                charmap[outcoord.Key, outcoord.Value] = output.ToString()[0];
                count += output;
            }

            Draw(charmap);

            var strgen = new StringBuilder();

            for (int i = 0; i < charmap.GetLength(0); i++)
            {
                for (int j = 0; j < charmap.GetLength(1); j++)
                {
                    strgen.Append(charmap[i, j]);
                }
                strgen.Append(Environment.NewLine);
            }

            var s = strgen.ToString();
        }