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}"); }
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}"); }
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)}"); } } } } } }
public string Compute(string[] input) { var computer = new IntCodeComputer(IntCodeProgramParser.Parse(input)); game = new Game(computer); game.Setup(); return($"{game.BlockTilesCount}"); }
public string Compute(string[] input) { var program = IntCodeProgramParser.Parse(input); var robot = new ScaffoldRobot(new IntCodeComputer(program)); robot.Run(); return($"{robot.AlignmentParamsSum}"); }
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}"); }
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}"); }
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}"); }
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}"); }
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($""); }
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}"); }
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}"); } }