Sha256: 60fdf1ccb3f7e693f92a72792a0c9bce441d22c85d927155c35517f36dafe5ea
Contents?: true
Size: 1.03 KB
Versions: 40
Compression:
Stored size: 1.03 KB
Contents
using System.Linq; public class Matrix { private readonly int[][] _rows; private readonly int[][] _cols; public Matrix(string input) { _rows = ParseRows(input); _cols = ParseCols(_rows); } public int Rows => _rows.Length; public int Cols => _cols.Length; public int[] Row(int row) => _rows[row]; public int[] Column(int col) => _cols[col]; private static int[][] ParseRows(string input) { return input.Split('\n') .Select(ParseRow) .ToArray(); } private static int[] ParseRow(string row) { return row.Split(' ') .Select(int.Parse) .ToArray(); } private static int[][] ParseCols(int[][] rows) { return Enumerable.Range(0, rows[0].Length) .Select(y => ParseCol(rows, y)) .ToArray(); } private static int[] ParseCol(int[][] rows, int y) { return Enumerable.Range(0, rows.Length) .Select(x => rows[x][y]) .ToArray(); } }
Version data entries
40 entries across 40 versions & 1 rubygems