예제 #1
0
        public string Compute(string[] input)
        {
            long noun = 0, verb = 0;
            long expectedOutput = 19690720;

            long[] program = IntCodeProgramParser.Parse(input);

            for (noun = 0; noun < 100; noun++)
            {
                for (verb = 0; verb < 100; verb++)
                {
                    var computer = new IntCodeComputer(program);
                    computer.Noun = noun;
                    computer.Verb = verb;
                    computer.RunIntcodeProgram();

                    if (computer.FirstValue == expectedOutput)
                    {
                        goto outside;
                    }
                }
            }

            outside : return($"{(100 * noun) + verb}");
        }
예제 #2
0
        public string Compute(string[] input)
        {
            var program = IntCodeProgramParser.Parse(input);

            var reach       = 0L;
            var gridSize    = 50;
            var validPoints = new List <Point>();

            // Count reachable
            for (var x = 0; x < gridSize; x++)
            {
                for (var y = 0; y < gridSize; y++)
                {
                    var computer = new IntCodeComputer(x, program);
                    var output   = computer.RunIntcodeProgram(y) ?? 0;
                    reach += output;
                    Console.WriteLine($"Output: {x} - {y} - {output} - Reach: {reach}");

                    if (output > 0)
                    {
                        validPoints.Add(new Point {
                            X = x, Y = y
                        });
                    }
                }
            }
            return($"{reach}");
        }
예제 #3
0
        public string ComputePartTwo(string[] input)
        {
            var program = IntCodeProgramParser.Parse(input);

            var gridSize    = 2000;
            var validPoints = new List <Point>();

            // Count reachable
            while (true)
            {
                for (var x = 0; x < gridSize; x++)
                {
                    for (var y = 0; y < gridSize; y++)
                    {
                        var computer = new IntCodeComputer(x, program);
                        var output   = computer.RunIntcodeProgram(y) ?? 0;

                        if (output == 1)
                        {
                            computer = new IntCodeComputer(x - 99, program);
                            output   = computer.RunIntcodeProgram(y + 99) ?? 0;

                            if (output == 1)
                            {
                                return($"Closest {(x-99) * 10000 + (y)}");
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        public string Compute(string[] input)
        {
            var computer = new IntCodeComputer(IntCodeProgramParser.Parse(input));

            game = new Game(computer);
            game.Setup();
            return($"{game.BlockTilesCount}");
        }
예제 #5
0
        public string Compute(string[] input)
        {
            var program = IntCodeProgramParser.Parse(input);
            var robot   = new ScaffoldRobot(new IntCodeComputer(program));

            robot.Run();
            return($"{robot.AlignmentParamsSum}");
        }
예제 #6
0
        public string ComputePartTwo(string[] input)
        {
            var maxMinutes = 0;
            var program    = IntCodeProgramParser.Parse(input);

            for (int i = 0; i < 1000; i++) // using stats for the filfiest hack in history of filthy hacks, it will eventually give the right answer
            {
                var computer = new IntCodeComputer(program);
                var explorer = new Explorer(computer, Point.Origin);
                computer.SetDatasource(explorer);

                try
                {
                    while (true)
                    {
                        explorer.Explore();
                    }
                }
                catch (Explorer.QuestCompletedException)
                {
                    var filled   = explorer.Map.Where(p => p.Value == Block.OxygenSystem).Select(p => p.Key).Distinct().ToList();
                    var fillable = explorer.Map.Where(p => p.Value != Block.Wall).Select(p => p.Key).Distinct().ToList();
                    var minutes  = 0;

                    while (fillable.Count > filled.Count)
                    {
                        var toFill = new List <Point>();
                        foreach (var filledPoint in filled)
                        {
                            foreach (var potentialFill in explorer.GetPotentialPointsInfo(filledPoint).Select(ff => ff.Value))
                            {
                                if (!filled.Contains(potentialFill) && fillable.Contains(potentialFill))
                                {
                                    toFill.Add(potentialFill);
                                }
                            }
                        }

                        foreach (var pointToFill in toFill.Distinct())
                        {
                            filled.Add(pointToFill);
                        }

                        minutes++;
                        // Console.WriteLine($"{minutes} minutes - {filled.Count}/{fillable.Count} filled");
                    }

                    maxMinutes = Math.Max(maxMinutes, minutes);
                    Console.WriteLine($"{minutes} vs {maxMinutes} minutes - {filled.Count}/{fillable.Count} filled");
                }
            }

            return($"{maxMinutes}");
        }
예제 #7
0
        public string Compute(string[] input)
        {
            var brain = new IntCodeComputer(IntCodeProgramParser.Parse(input));

            robot = new Robot(brain, PanelColor.Black);
            brain.AddDelegate(robot);
            brain.SetDatasource(robot);

            robot.Run();
            return($"{robot.UniquePanelsPaintedCount}");
        }
예제 #8
0
        public string ComputePartTwo(string[] input)
        {
            var program = IntCodeProgramParser.Parse(input);

            program[0] = 2;
            var computer = new IntCodeComputer(program);

            game = new Game(computer);
            computer.SetDatasource(game);
            game.Setup();
            return($"Game over: {game.Score}");
        }
예제 #9
0
        public string ComputePartTwo(string[] input)
        {
            var program = IntCodeProgramParser.Parse(input);

            program[0] = 2;
            var computer = new IntCodeComputer(program);
            var inputer  = new Inputer(computer);

            computer.SetDatasource(inputer);
            inputer.Run();
            return($"{inputer.Output}");
        }
예제 #10
0
        public string ComputePartTwo(string[] input)
        {
            var brain = new IntCodeComputer(IntCodeProgramParser.Parse(input));

            robot = new Robot(brain, PanelColor.White);
            brain.AddDelegate(robot);
            brain.AddDelegate(this);
            brain.SetDatasource(robot);

            robot.Run();
            return($"");
        }
예제 #11
0
        public string Compute(string[] input)
        {
            program = IntCodeProgramParser.Parse(input);

            int[] phaseSettings = new int[] { 5, 6, 7, 8, 9 };

            foreach (var permuation in phaseSettings.Permutations())
            {
                maxOutput = Math.Max(maxOutput, new IntCodeAmplifier(permuation, program).Run());
            }

            return($"{maxOutput}");
        }
예제 #12
0
        public string Compute(string[] input)
        {
            var computer = new IntCodeComputer(IntCodeProgramParser.Parse(input));
            var explorer = new Explorer(computer, Point.Origin);

            computer.SetDatasource(explorer);

            try
            {
                while (true)
                {
                    explorer.Explore();
                }
            }
            catch (Explorer.QuestCompletedException)
            {
                var map = explorer.Map;
                return($"{explorer.Distance}");
            }
        }