예제 #1
0
    char[,] Step(char[,] board, NeighboursDelegate neighbours, int emptyCutoff)
    {
        var newBoard = (char[, ])board.Clone();

        for (int i = 0; i < board.GetLength(0); ++i)
        {
            for (int j = 0; j < board.GetLength(1); ++j)
            {
                newBoard[i, j] = board[i, j] switch
                {
                    'L' => neighbours(board, i, j).All(c => c is not '#')
                    ? '#'
                    : 'L',
                    '#' => neighbours(board, i, j).Count(c => c is '#') >= emptyCutoff
                    ? 'L'
                    : '#',
                    char c => c,
                }
            }
        }
        ;

        return(newBoard);
    }
예제 #2
0
 int Solve(char[,] input, NeighboursDelegate neighbours, int emptyCutoff) =>
 LINQExtensions.DoWhile(
     x => !LINQExtensions.MatrixEquals(x.Prev, x.Stepped),
     x => (x.Stepped, Step(x.Stepped, neighbours, emptyCutoff)),
     (Prev: input, Stepped: Step(input, neighbours, emptyCutoff)))