Cody

Solution 1542623

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]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 2 2 3 3 5 3 5 5 1 1 3 5 1 3 3 4 4 v = 3000 0 0 0 0 mat = 5 4 2 1 1 10 5 1 2 1 50 3 2 3 3 100 3 1 1 1 200 2 4 1 5 600 4 5 3 3 3000 5 5 4 3 12000 2 2 3 2 1 4 3 3 2 5 1 5 4 4 4 1 5 5 1 1 4 4 2 2 3 3 5 3 5 5 1 1 3 5 1 3 3 4 4 v = 12000 0 0 0 0 mat = 5 4 2 1 1 10 5 1 2 1 50 3 2 3 3 100 3 1 1 1 200 2 4 1 5 600 4 5 3 3 3000 5 5 4 3 12000 2 2 3 2 12000 4 3 3 2 5 1 5 4 4 4 1 5 5 1 1 4 4 2 2 3 3 5 3 5 5 1 1 3 5 1 3 3 4 4 v = 12000 0 0 0 0 mat = 5 4 2 1 1 10 5 1 2 1 50 3 2 3 3 100 3 1 1 1 200 2 4 1 5 600 4 5 3 3 3000 5 5 4 3 12000 2 2 3 2 12000 4 3 3 2 60000 1 5 4 4 4 1 5 5 1 1 4 4 2 2 3 3 5 3 5 5 1 1 3 5 1 3 3 4 4 v = 60000 0 0 0 0 mat = 5 4 2 1 1 10 5 1 2 1 50 3 2 3 3 100 3 1 1 1 200 2 4 1 5 600 4 5 3 3 3000 5 5 4 3 12000 2 2 3 2 12000 4 3 3 2 60000 1 5 4 4 240000 1 5 5 1 1 4 4 2 2 3 3 5 3 5 5 1 1 3 5 1 3 3 4 4 v = 240000 0 0 0 0 mat = 5 4 2 1 1 10 5 1 2 1 50 3 2 3 3 100 3 1 1 1 200 2 4 1 5 600 4 5 3 3 3000 5 5 4 3 12000 2 2 3 2 12000 4 3 3 2 60000 1 5 4 4 240000 1 5 5 1 240000 4 4 2 2 3 3 5 3 5 5 1 1 3 5 1 3 3 4 4 v = 240000 0 0 0 0 mat = 5 4 2 1 1 10 5 1 2 1 50 3 2 3 3 100 3 1 1 1 200 2 4 1 5 600 4 5 3 3 3000 5 5 4 3 12000 2 2 3 2 12000 4 3 3 2 60000 1 5 4 4 240000 1 5 5 1 240000 4 4 2 2 720000 3 5 3 5 5 1 1 3 5 1 3 3 4 4 v = 720000 0 0 0 0 mat = 5 4 2 1 1 10 5 1 2 1 50 3 2 3 3 100 3 1 1 1 200 2 4 1 5 600 4 5 3 3 3000 5 5 4 ...