6 kyu
Matrix Addition
4,278 of 13,951xDranik
Description:
Write a function that accepts two square matrices (N x N
two dimensional arrays), and return the sum of the two. Both matrices being passed into the function will be of size N x N
(square), containing only integers.
How to sum two matrices:
Take each cell [n][m]
from the first matrix, and add it with the same [n][m]
cell from the second matrix. This will be cell [n][m]
of the solution matrix. (Except for C where solution matrix will be a 1d pseudo-multidimensional array).
Visualization:
|1 2 3| |2 2 1| |1+2 2+2 3+1| |3 4 4|
|3 2 1| + |3 2 3| = |3+3 2+2 1+3| = |6 4 4|
|1 1 1| |1 1 3| |1+1 1+1 1+3| |2 2 4|
Example
matrixAddition(
[ [1, 2, 3],
[3, 2, 1],
[1, 1, 1] ],
// +
[ [2, 2, 1],
[3, 2, 3],
[1, 1, 3] ] )
// returns:
[ [3, 4, 4],
[6, 4, 4],
[2, 2, 4] ]
Matrix
Arrays
Algorithms
Similar Kata:
Stats:
Created | Oct 19, 2013 |
Published | Oct 19, 2013 |
Warriors Trained | 21407 |
Total Skips | 2322 |
Total Code Submissions | 32677 |
Total Times Completed | 13951 |
JavaScript Completions | 4278 |
CoffeeScript Completions | 134 |
Ruby Completions | 930 |
C# Completions | 658 |
PHP Completions | 462 |
Python Completions | 3445 |
C++ Completions | 1297 |
Java Completions | 2224 |
C Completions | 517 |
Elixir Completions | 106 |
Lua Completions | 128 |
NASM Completions | 10 |
Rust Completions | 93 |
Scala Completions | 16 |
TypeScript Completions | 174 |
Total Stars | 255 |
% of votes with a positive feedback rating | 92% of 1519 |
Total "Very Satisfied" Votes | 1303 |
Total "Somewhat Satisfied" Votes | 185 |
Total "Not Satisfied" Votes | 31 |