static void Part1(Int64[] input) { var bot = new ASCIIRobot(input, null); bot.Brain.Run(); var output = bot.Brain.GetOutputQueue(); var map = new List <Int64>(); while (output.Any()) { map.Add(output.Dequeue()); } Display(map); var mapCoords = new List <Coords>(); long x = 0; long y = 0; foreach (var l in map) { if (l == 10) { ++y; x = 0; continue; } else { Map.Add(new Coords(x++, y, 0, (Tile)l)); } } long maxX = Map.Max(c => c.X); long maxY = Map.Max(c => c.Y); int sum = 0; for (int j = 1; j < maxY - 1; ++j) { for (int i = 1; i < maxX - 1; ++i) { var current = Map.Where(c => c.X == i && c.Y == j).First(); if (current.Tile == Tile.Scaffold) { if (Map.Exists(c => (current.X == c.X - 1 && current.Y == c.Y && c.Tile == Tile.Scaffold)) && Map.Exists(c => (current.X == c.X + 1 && current.Y == c.Y && c.Tile == Tile.Scaffold)) && Map.Exists(c => (current.X == c.X && current.Y == c.Y - 1 && c.Tile == Tile.Scaffold)) && Map.Exists(c => (current.X == c.X && current.Y == c.Y + 1 && c.Tile == Tile.Scaffold))) { sum += i * j; } } } } Console.WriteLine($"Part 1: {sum}"); }
static void Part2(Int64[] input) { var M = new Int64[] { 'A', ',', 'B', ',', 'B', ',', 'A', ',', 'B', ',', 'C', ',', 'A', ',', 'C', ',', 'B', ',', 'C', '\n' }; var A = new Int64[] { 'L', ',', '4', ',', 'L', ',', '6', ',', 'L', ',', '8', ',', 'L', ',', '1', '2', '\n' }; var B = new Int64[] { 'L', ',', '8', ',', 'R', ',', '1', '2', ',', 'L', ',', '1', '2', '\n' }; var C = new Int64[] { 'R', ',', '1', '2', ',', 'L', ',', '6', ',', 'L', ',', '6', ',', 'L', ',', '8', '\n' }; var V = new Int64[] { 'n', 10 }; input[0] = 2; var bot = new ASCIIRobot(input, null); bot.Brain.Run(); var output = bot.Brain.GetOutputQueue(); var map = new List <Int64>(); while (output.Any()) { map.Add(output.Dequeue()); } Display(map); foreach (var c in M) { bot.Brain.SendInput(c); Console.Write((char)c); } bot.Brain.Run(); map = new List <Int64>(); while (output.Any()) { map.Add(output.Dequeue()); } Display(map); foreach (var c in A) { bot.Brain.SendInput(c); Console.Write((char)c); } bot.Brain.Run(); map = new List <Int64>(); while (output.Any()) { map.Add(output.Dequeue()); } Display(map); foreach (var c in B) { bot.Brain.SendInput(c); Console.Write((char)c); } bot.Brain.Run(); map = new List <Int64>(); while (output.Any()) { map.Add(output.Dequeue()); } Display(map); foreach (var c in C) { bot.Brain.SendInput(c); Console.Write((char)c); } bot.Brain.Run(); map = new List <Int64>(); while (output.Any()) { map.Add(output.Dequeue()); } Display(map); foreach (var c in V) { bot.Brain.SendInput(c); Console.Write((char)c); } bot.Brain.Run(); map = new List <Int64>(); while (output.Any()) { map.Add(output.Dequeue()); } Display(map); bot.Brain.Run(); if (bot.Brain.GetOutputQueue().Any()) { Console.WriteLine($"Part 2: {bot.Brain.GetOutputQueue().Dequeue()}"); } }