Exemplo n.º 1
0
        private long Solve(List <string> input, Func <int, int, int> CountSeatsAround, int clearAround)
        {
            WaitingArea     = input.ToList();
            WaitingRoomMaxY = WaitingArea.Count - 1;
            WaitingRoomMaxX = WaitingArea.First().Length - 1;

            var occupied = -1;

            while (occupied != OccupiedWaitingRoom)
            {
                occupied = OccupiedWaitingRoom;

                var copy = WaitingArea.Select(x => x.ToCharArray()).ToList();
                for (var y = 0; y <= WaitingRoomMaxY; y++)
                {
                    for (var x = 0; x <= WaitingRoomMaxX; x++)
                    {
                        if (copy[y][x] == Floor)
                        {
                            continue;
                        }

                        var occupiedAround = CountSeatsAround(y, x);
                        if (copy[y][x] == EmptySeat && occupiedAround == 0)
                        {
                            copy[y][x] = OccupiedSeat;
                        }
                        if (copy[y][x] == OccupiedSeat && occupiedAround >= clearAround)
                        {
                            copy[y][x] = EmptySeat;
                        }
                    }
                }

                WaitingArea = copy.Select(x => string.Join("", x)).ToList();
                var output = string.Join(Environment.NewLine, WaitingArea);
            }

            return(OccupiedWaitingRoom);
        }