Cody

Solution 1548447

Submitted on 4 Jun 2018 by tamir zinger
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 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 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 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 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 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 mat = 1 2 3 4 5 6 7 2 2 3 4 5 v = 5 0 0 mat = 1 2 3 4 5 12 7 2 2 3 4 5 v = 5 12 0 mat = 1 2 3 4 5 12 21 2 2 3 4 5 v = 5 12 21 mat = 1 2 3 4 5 12 21 8 2 3 4 5 v = 5 12 21 8 mat = 1 2 3 4 5 12 21 8 10 3 4 5 v = 10 12 21 8 mat = 1 2 3 4 5 12 21 8 10 36 4 5 v = 10 36 21 8 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 = rand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