public static int[] ColumnSum_PerColumn(this int[,] array2D)
        {
            int numColumns = array2D.NumColumns();

            int[] columnSum_PerColumn = new int[numColumns];
            for (int columnIndex = 0; columnIndex < numColumns; columnIndex++)
            {
                columnSum_PerColumn[columnIndex] = array2D.Column(columnIndex).Sum();
            }
            return(columnSum_PerColumn);
        }
Exemplo n.º 2
0
        public void GetColumn()
        {
            int[,] x =
            {
                { 11, 12, 13, 14, 15 },
                { 21, 22, 23, 24, 25 },
                { 31, 32, 33, 34, 35 },
                { 41, 42, 43, 44, 45 }
            };

            Assert.Equal(new[] { 12, 22, 32, 42 }, x.Column(1));
        }
Exemplo n.º 3
0
    public static IEnumerable <(int, int)> Calculate(int[,] matrix)
    {
        for (var row = 0; row < matrix.RowCount(); row++)
        {
            for (var col = 0; col < matrix.ColumnCount(); col++)
            {
                if (IsSaddlePoint(row, col))
                {
                    yield return(row + 1, col + 1);
                }
            }
        }

        bool IsSaddlePoint(int row, int col)
        {
            var value = matrix[row, col];

            return(matrix.Row(row).All(n => n <= value) &&
                   matrix.Column(col).All(n => n >= value));
        }
    }