Ejemplo n.º 1
0
        public override async ValueTask <string> Solve_1()
        {
            var flashCout = 0;

            for (int i = 0; i < 100; i++)
            {
                foreach (var item in _input)
                {
                    _input[item.pos]++;
                }
                List <(System.Drawing.Point pos, char value)> toFlash = new();
                do
                {
                    toFlash = _input.Where(x => x.value > '9' && x.value != '+').ToList();
                    foreach (var item in toFlash)
                    {
                        _input[item.pos] = '+';
                        flashCout++;
                        var neigh = _input.Get8NeighborsOf(item.pos);
                        foreach (var n in neigh.Where(x => _input[x] != '+'))
                        {
                            _input[n]++;
                        }
                    }
                } while (toFlash.Any());

                foreach (var item in _input.Where(x => x.value == '+'))
                {
                    _input[item.pos] = '0';
                }
            }
            return(flashCout.ToString());
        }
Ejemplo n.º 2
0
        private char?Life(Point pos)
        {
            /*
             * If a seat is empty (L) and there are no occupied seats adjacent to it, the seat becomes occupied.
             * If a seat is occupied (#) and four or more seats adjacent to it are also occupied, the seat becomes empty.
             * Otherwise, the seat's state does not change.
             */
            var occupiedN = grid.Get8NeighborsOf(pos).Count(c => grid[c] == '#');

            if (grid[pos] == 'L' && occupiedN == 0)
            {
                return('#');
            }
            if (grid[pos] == '#' && occupiedN >= 4)
            {
                return('L');
            }
            return(null);
        }