static char[,] ExpandProblem(char[,] arr) { Span2D <char> insert = new char[, ] { { ' ', ' ', '#', 'D', '#', 'C', '#', 'B', '#', 'A', '#', ' ', ' ' }, { ' ', ' ', '#', 'D', '#', 'B', '#', 'A', '#', 'C', '#', ' ', ' ' }, }; var span = arr.AsSpan2D(); var expanded = new char[span.Height + 2, span.Width]; var expandedSpan = expanded.AsSpan2D(); span[0..3, ..].CopyTo(expandedSpan[0..3, ..]);
static char[,] CombineTiles(Tile[,] puzzle) { var tileSize = puzzle[0, 0].Top.Length - 2; var tileCount = puzzle.GetLength(0); var imageSize = tileSize * tileCount; var image = new char[imageSize, imageSize]; var span = image.AsSpan2D(); for (var row = 0; row < puzzle.GetLength(0); row++) { for (var column = 0; column < puzzle.GetLength(1); column++) { var rowStart = row * tileSize; var colStart = column * tileSize; var dest = span[rowStart..(rowStart + tileSize), colStart..(colStart + tileSize)];
static char[,] ApplyRules(char[,] input, RuleSet rules, int size) { var memory = input.AsMemory2D(); var panels = input.GetLength(0) / size; var resultSize = size + 1; var newSize = resultSize * panels; var result = new char[newSize, newSize]; var resultSpan = result.AsSpan2D(); for (var y = 0; y < panels; y++) { var yOffset = y * size; var resultYOffset = y * resultSize; for (var x = 0; x < panels; x++) { var xOffset = x * size; var resultXOffset = x * resultSize; var target = resultSpan[resultXOffset..(resultXOffset + resultSize), resultYOffset..(resultYOffset + resultSize)];