Exemplo n.º 1
0
        public override int SolvePart1()
        {
            var grid = new HexGrid2D(directionsList.Max(d => d.Directions.Count()) * 2);

            foreach (var d in directionsList)
            {
                grid.FlipTileAt(d.Location);
            }
            return(grid.ValueCounters[TileColor.Black]);
        }
Exemplo n.º 2
0
        public override int SolvePart2()
        {
            // Shamelessly copied the logic from D17
            const int days = 100;

            var defaultGrid = new HexGrid2D(directionsList.Max(d => d.Directions.Count()) * 2);

            foreach (var d in directionsList)
            {
                defaultGrid.FlipTileAt(d.Location);
            }

            var grid = defaultGrid.ExpandForDays(days);

            // There really could be many more improvements, just like in the solution for D17
            // But I would rather bother with this while abstracting some of the expansion logic
            for (int i = 1; i <= days; i++)
            {
                var tempGrid      = new HexGrid2D(grid);
                var currentOffset = grid.Center - defaultGrid.Center - new Location2D(i);
                var currentSpace  = defaultGrid.Dimensions + new Location2D(i * 2);

                for (int x = 0; x < currentSpace.X; x++)
                {
                    for (int y = 0; y < currentSpace.Y; y++)
                    {
                        var currentLocation = (x, y) + currentOffset;

                        var value     = grid[currentLocation];
                        int adjacents = grid.GetAdjacentValues(currentLocation, TileColor.Black);
                        tempGrid[currentLocation] = (value, adjacents) switch
                        {
                            (TileColor.Black, 0 or > 2) => TileColor.White,
                            (TileColor.White, 2) => TileColor.Black,
                            _ => value
                        };
                    }
                }

                grid = tempGrid;
            }

            return(grid.ValueCounters[TileColor.Black]);
        }
Exemplo n.º 3
0
 public HexGrid2D(HexGrid2D other, Location2D dimensions, Location2D offset)
     : base(other, dimensions, offset)
 {
 }
Exemplo n.º 4
0
 public HexGrid2D(HexGrid2D other)
     : base(other)
 {
 }