public static int Part2(string inputText) { var program = new IntCodeProgram(InputParser.ListOfLongs(inputText, ','), 0, 0); var robot = new EHPR(program); robot.Painting.Add(new Vector2Int(0, 0), new List <long>(new long[] { 1 })); robot.Run(); AOCExecutor.ActionForMain.Enqueue(() => WriteToFilePainting(robot.Painting, "Day11_Part2.txt")); var bounds = MathUtils.FindBound(robot.Painting.Keys.ToList()); int xOff = -bounds.xMin; int yOff = -bounds.yMin; Debug.Log(bounds); var image = new int[bounds.size.y + 1, bounds.size.x + 1]; foreach (var pt in robot.Painting) { if (pt.Key.x < bounds.min.x || pt.Key.x > bounds.max.x || pt.Key.y < bounds.min.y || pt.Key.y > bounds.max.y) { Debug.Log($"Contains pas {pt.Key}"); } if (pt.Value.Count == 0) { continue; } var value = pt.Value.Last(); image[bounds.size.y - (pt.Key.y + yOff), pt.Key.x + xOff] = (int)value; } AOCExecutor.ActionForMain.Enqueue(() => Day8Main.ImageToTexturee(image, bounds.size.x + 1, bounds.size.y + 1, AOCUI.Instance.Part1ComputeOutput)); return(2); }
public void Part2_Exemple1() { var layers = Day8Main.InputToImageLayers(new int[] { 0, 2, 2, 2, 1, 1, 2, 2, 2, 2, 1, 2, 0, 0, 0, 0 }, 2, 2); var image = Day8Main.GetImage(layers); Assert.AreEqual(new int[, ] { { 0, 1 }, { 1, 0 } }, image); }
public void Exemple1_Pixels() { var layers = Day8Main.InputToImageLayers(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2 }, 3, 2); Assert.AreEqual(new int[, ] { { 1, 2, 3 }, { 4, 5, 6 } }, layers[0].ImagePixels); Assert.AreEqual(new int[, ] { { 7, 8, 9 }, { 0, 1, 2 } }, layers[1].ImagePixels); }
private static void MakeImageForGrid(int[,] orderGrid, int vaporizorX, int vaporizorY) { var w = orderGrid.GetLength(1); var h = orderGrid.GetLength(0); var image = new Color32[h, w]; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if (orderGrid[y, x] == 0) { image[y, x] = Color.black; } else { image[y, x] = Color.Lerp(Color.white, Color.red, orderGrid[y, x] / 255f); } } } image[vaporizorY, vaporizorX] = Color.green; AOCExecutor.ActionForMain.Enqueue(() => Day8Main.ImageToTexturee(image, w, h, AOCUI.Instance.Part1ComputeOutput)); }
private void CreateTaskForDay(int currentDay) { var input = AOCInput.GetInput(currentDay); if (currentDay == 1) { CreateTask(() => Day1Main.Part1(input), () => Day1Main.Part2(input)); Day1Main.StartPart1ComputeShader(input); } else if (currentDay == 2) { CreateTask(() => Day2Main.Part1(input), () => Day2Main.Part2(input)); } else if (currentDay == 3) { CreateTask(() => Day3Main.Part1(input) + "", () => Day3Main.Part2(input) + ""); } else if (currentDay == 4) { CreateTask(() => Day4Main.Part1(input) + "", () => Day4Main.Part2(input) + ""); } else if (currentDay == 5) { CreateTask(() => Day5Main.Part1(input) + "", () => Day5Main.Part2(input) + ""); } else if (currentDay == 6) { CreateTask(() => Day6Main.Part1(input) + "", () => Day6Main.Part2(input) + ""); } else if (currentDay == 7) { CreateTask(() => Day7Main.Part1(input) + "", () => Day7Main.Part2(input) + ""); } else if (currentDay == 8) { CreateTask(() => Day8Main.Part1(input) + "", () => Day8Main.Part2(input) + ""); } else if (currentDay == 9) { CreateTask(() => Day9Main.Part1(input) + "", () => Day9Main.Part2(input) + ""); } else if (currentDay == 10) { CreateTask(() => Day10Main.Part1(input) + "", () => Day10Main.Part2(input) + ""); } else if (currentDay == 11) { CreateTask(() => Day11Main.Part1(input) + "", () => Day11Main.Part2(input) + ""); } else if (currentDay == 12) { CreateTask(() => Day12Main.Part1(input) + "", () => Day12Main.Part2(input) + ""); } else if (currentDay == 13) { CreateTask(() => Day13Main.Part1(input) + "", () => Day13Main.Part2(input) + ""); } else if (currentDay == 14) { CreateTask(() => Day14Main.Part1(input) + "", () => Day14Main.Part2(input) + ""); } else if (currentDay == 15) { CreateTask(() => Day15Main.Part1(input) + "", () => Day15Main.Part2(input) + ""); } }
public void Exemple1_Has2Layers() { var layers = Day8Main.InputToImageLayers(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2 }, 3, 2); Assert.AreEqual(2, layers.Length, "Has 2 layers"); }