public override async ValueTask <string> Solve_1() { var grid = _img; var infChar = '.'; var infCharToggle = _algo[0] == '#'; for (int i = 0; i < 2; i++) { grid = new FiniteGrid2D <char>(grid, 1, infChar); var nextgrid = new FiniteGrid2D <char>(grid); foreach (var(pos, _) in grid) { var area = AreaToIndex(grid.GetPointWith8Neighbors(pos, infChar)); nextgrid[pos] = _algo[area]; } grid = nextgrid; if (infCharToggle) { infChar = infChar == '.' ? '#' : '.'; } } //Console.WriteLine(grid.ToString()); return(grid.Count(cell => cell.value == '#').ToString()); }
public override async ValueTask <string> Solve_2() { var grid = _img; var infChar = '.'; var infCharToggle = _algo[0] == '#'; for (int i = 0; i < 50; i++) { var inflated = grid.Bounds.InflatedCopy(1, 1); grid = new FiniteGrid2D <char>(inflated, Step); if (infCharToggle) { infChar = infChar == '.' ? '#' : '.'; } } //Console.WriteLine(grid.ToString()); return(grid.Count(cell => cell.value == '#').ToString()); char Step(Point p) { var area = grid.GetPointWith8Neighbors(p, infChar); return(_algo[AreaToIndex(area)]); } }
public override string Solve_1() { var hasChanged = false; do { hasChanged = false; var newgrid = new FiniteGrid2D <char>(grid); foreach (var(pos, value) in grid.Where(cell => cell.value != '.')) { var newv = Life(pos); if (newv != null) { newgrid[pos] = newv.Value; hasChanged = true; } } grid = newgrid; } while (hasChanged); return(grid.Count(cell => cell.value == '#').ToString()); }