Cody

# Problem 44467. Product of Each Column

Solution 1542628

Submitted on 29 May 2018 by uri wolf
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('myProd.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Pass
filetext = fileread('myProd.m'); assert(isempty(strfind(filetext, 'prod')),'Cannot use prod() function')

3   Pass
mat = ones(5); v_correct = ones(1, 5); assert(isequal(myProd(mat),v_correct))

n = 5 m = 5 v = 0 0 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 0 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 0 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 0 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 0 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 0 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 0 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 1 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 1 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 1 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 1 0 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 1 1 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 1 1 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 1 1 mat = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 1 1 1 1 1

4   Pass
mat = [ 1, 2, 3, 4; 5, 6, 7, 2; 2, 3, 4, 5]; v_correct = [10, 36, 84, 40]; assert(isequal(myProd(mat),prod(mat)))

n = 3 m = 4 v = 0 0 0 0 mat = 1 2 3 4 5 6 7 2 2 3 4 5 v = 5 0 0 0 mat = 1 2 3 4 5 6 7 2 10 3 4 5 v = 10 0 0 0 mat = 1 2 3 4 5 12 7 2 10 3 4 5 v = 10 12 0 0 mat = 1 2 3 4 5 12 7 2 10 36 4 5 v = 10 36 0 0 mat = 1 2 3 4 5 12 21 2 10 36 4 5 v = 10 36 21 0 mat = 1 2 3 4 5 12 21 2 10 36 84 5 v = 10 36 84 0 mat = 1 2 3 4 5 12 21 8 10 36 84 5 v = 10 36 84 8 mat = 1 2 3 4 5 12 21 8 10 36 84 40 v = 10 36 84 40

5   Pass
m = randi([5,15]); n = randi([5,15]); mat = randi(5, n, m); v_correct = prod(mat); assert(isequal(myProd(mat),prod(mat)))

n = 10 m = 5 v = 0 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 5 1 2 1 3 5 4 3 5 4 1 5 1 3 2 1 1 2 5 1 5 4 4 5 5 5 3 2 2 1 3 5 5 5 4 1 3 5 1 1 v = 15 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 75 1 2 1 3 5 4 3 5 4 1 5 1 3 2 1 1 2 5 1 5 4 4 5 5 5 3 2 2 1 3 5 5 5 4 1 3 5 1 1 v = 75 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 75 1 2 1 3 375 4 3 5 4 1 5 1 3 2 1 1 2 5 1 5 4 4 5 5 5 3 2 2 1 3 5 5 5 4 1 3 5 1 1 v = 375 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 75 1 2 1 3 375 4 3 5 4 375 5 1 3 2 1 1 2 5 1 5 4 4 5 5 5 3 2 2 1 3 5 5 5 4 1 3 5 1 1 v = 375 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 75 1 2 1 3 375 4 3 5 4 375 5 1 3 2 375 1 2 5 1 5 4 4 5 5 5 3 2 2 1 3 5 5 5 4 1 3 5 1 1 v = 375 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 75 1 2 1 3 375 4 3 5 4 375 5 1 3 2 375 1 2 5 1 1875 4 4 5 5 5 3 2 2 1 3 5 5 5 4 1 3 5 1 1 v = 1875 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 75 1 2 1 3 375 4 3 5 4 375 5 1 3 2 375 1 2 5 1 1875 4 4 5 5 9375 3 2 2 1 3 5 5 5 4 1 3 5 1 1 v = 9375 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 75 1 2 1 3 375 4 3 5 4 375 5 1 3 2 375 1 2 5 1 1875 4 4 5 5 9375 3 2 2 1 28125 5 5 5 4 1 3 5 1 1 v = 28125 0 0 0 0 mat = 5 2 1 3 1 15 5 3 2 3 75 1 2 1 3 375 4 3 5 4 375 5 1 3 2 375 1 2 5 1 1875 4 4 5 5 9375 3 2 2 1 28125 5 5 5 4 28125 3 5 1 1 v = 28125 0 0 0 0 mat = 5 2 1 3 1 15 10 3 2 3 75 1 2 1 3 375 4 3 5 4 375 5 1 3 2 375 1 2 5 1 1875 4 4 5 5 9375 3 2 2 1 28125 5 5 5 4 28125 3 5 1 1 v = 28125 10 0 0 0 mat = 5 2 1 3 1 15 10 3 2 3 75 10 2 1 3 375 4 3 5 4 375 5 1 3 2 375 1 2 5 1 1875 4 4 5 5 9375 3 2 2 1 28125 5 5 5 4 28125 3 5 1 1 v = 28125 10 0 0 0 mat = 5 2 1 3 1 15 10 3 2 3 75 10 2 1 3 375 40 3 5 4 375 5 1 3 2 375 1 2 5 1 1875 4 4 5 5 9375 3 2 2 1 28125 5 5 5 4 28125 3 5 1 1 v = 28125 40 0 0 0 mat = 5 2 1 3 1 15 10 3 2 3 75 10 2 1 3 375 40 3 5 4 375 200 1 3 2 375 1 2 5 1 1875 4 4 5 5 9375 3 2 2 1 28125 5 5 5 4 28125 3 5 1 1 v = 28125 200 0 0 0 mat = 5 2 1 3 1 15 10 3 2 3 75 10 2 1 3 375 40 3 5 4 375 200 1 3 2 375 200 2 5 1 1875 4 4 5 5 9375 3 2 2 1 28125 5 5 5 4 28125 3 5 1 1 v = 28125 200 0 0 0 mat = 5 2 1 3 1 15 10 3 2 3 75 10 2 1 3 375 40 3 5 4 375 200 1 3 2 375 200 2 5 1 1875 800 4 5 5 9375 3 2 2 1 28125 5 5 5 4 28125 3 5 1 1 v = 28125 800 0 0 0 mat = 5 2 1 3 1 15 10 3 2 3 75 10 2 1 3 375 40 3 5 4 375 200 1 3 2 375 200 2 5 1 1875 800 4 5 5 9375 2400 2 2 1 28125 5 5 5 4 28125 3 5 1 1 v = 28125 2400 0 0 0 mat = 5 2 1 3 1 15 10 3 2 3 75 10 2 1 3 375 40 3 5 4 375 200 1 3 2 375 200 2 5 1 1875 800 4 5 5 9375 2400 2 2 1 28125 12000 5 5 4 28125 3 5...

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!