Cody

# Problem 44467. Product of Each Column

Solution 1545892

Submitted on 1 Jun 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
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