static void P1() { var lines = Utilities.GetStringFromFile("Day13.txt").SplitLongArrayFromString(','); var vm = new IntCodeVM(new IntCodeVMConfiguration() { }); vm.WriteProgram(lines); //vm.WriteMemory(0, 1); vm.RunProgram(); processOutputs(vm); Draw(grid); var blockcount = 0; for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { if (grid[i, j] == 'B') { blockcount++; } } } }
public static void P1() { var lines = Utilities.GetStringFromFile("Day17.txt").SplitLongArrayFromString(','); var vm = new IntCodeVM(new IntCodeVMConfiguration() { }); vm.WriteProgram(lines); char[,] charmap = new char[41, 49]; while (vm.RunProgram() == HALTTYPE.HALT_WAITING) { break; } string map = ""; int J = 0; int I = 0; while (vm.outputs.Count > 0) { char tile; tile = (char)vm.outputs.Dequeue(); map += tile; if (tile == 10) { J++; I = 0; } else { charmap[J, I] = tile; I++; } } int score = 0; for (int i = 1; i < charmap.GetLength(1) - 1; i++) { for (int j = 1; j < charmap.GetLength(0) - 1; j++) { if (charmap[j, i] == '#' && (charmap[j, i - 1] == '#' && charmap[j, i + 1] == '#' && charmap[j - 1, i] == '#' && charmap[j + 1, i] == '#')) { score += i * j; } } } Console.Write(map); }
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()); }
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); }
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) { } }
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}"); }
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(); }