Solved: 14 - Multidimensional
This commit is contained in:
@@ -1,9 +1,32 @@
|
||||
#include "multidimensional.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
namespace arrays {
|
||||
|
||||
auto create_matrix(int rows, int cols, int fill) -> Matrix { (void)rows; (void)cols; (void)fill; return {}; }
|
||||
auto transpose(const Matrix& matrix) -> Matrix { (void)matrix; return {}; }
|
||||
auto row_sums(const Matrix& matrix) -> std::vector<int> { (void)matrix; return {}; }
|
||||
auto create_matrix(const int rows, const int cols, const int fill) -> Matrix {
|
||||
return Matrix(rows, std::vector(cols, fill));
|
||||
}
|
||||
|
||||
auto transpose(const Matrix& matrix) -> Matrix {
|
||||
auto new_mat = Matrix(matrix[0].size(), std::vector(matrix.size(), 0));
|
||||
for (size_t row = 0; row < matrix.size(); ++row) {
|
||||
for (size_t col = 0; col < matrix[row].size(); ++col) {
|
||||
new_mat[col][row] = matrix[row][col];
|
||||
}
|
||||
}
|
||||
return new_mat;
|
||||
}
|
||||
|
||||
auto row_sums(const Matrix& matrix) -> std::vector<int> {
|
||||
auto sums = std::vector(matrix.size(), 0);
|
||||
auto idx = 0;
|
||||
for (auto row: matrix) {
|
||||
sums[idx] = std::ranges::fold_left(row, 0, std::plus{});
|
||||
idx++;
|
||||
}
|
||||
return sums;
|
||||
}
|
||||
|
||||
} // namespace arrays
|
||||
|
||||
Reference in New Issue
Block a user