Ejemplo n.º 1
0
        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)]);
            }
        }
Ejemplo n.º 2
0
        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());
        }