Cody

Problem 44889. Given a matrix A return a vector of the product of the elements in each column using a loop without using prod.

Solution 2655719

Submitted on 5 Jul 2020 by Ramesh Kumar V
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
x = [8 10 9 9 1 8 3 2 4 4 10 4 6 2 7 7 1 6 4 1]; y_correct = [4480 120 648 288 28]; assert(isequal(ProdMat(x),y_correct))

m = 4 n = 5 y = [] p = 1 p = 8 p = 64 p = 640 p = 4480 y = 4480 p = 1 p = 10 p = 30 p = 120 p = 120 y = 4480 120 p = 1 p = 9 p = 18 p = 108 p = 648 y = 4480 120 648 p = 1 p = 9 p = 36 p = 72 p = 288 y = 4480 120 648 288 p = 1 p = 1 p = 4 p = 28 p = 28 y = 4480 120 648 288 28

2   Pass
x = [7 4 1 4 5 3 7 5 7 1 6 6 6 9 8 2 2 8 6 7 9 8 4 9 6 7 5 1 2 8 9 3 5 5 7 9]; y_correct = [42 336 432 1728 540 1080 420 490 2520]; assert(isequal(ProdMat(x),y_correct))

m = 4 n = 9 y = [] p = 1 p = 7 p = 7 p = 42 p = 42 y = 42 p = 1 p = 4 p = 24 p = 168 p = 336 y = 42 336 p = 1 p = 1 p = 6 p = 54 p = 432 y = 42 336 432 p = 1 p = 4 p = 24 p = 192 p = 1728 y = 42 336 432 1728 p = 1 p = 5 p = 45 p = 180 p = 540 y = 42 336 432 1728 540 p = 1 p = 3 p = 24 p = 216 p = 1080 y = 42 336 432 1728 540 1080 p = 1 p = 7 p = 14 p = 84 p = 420 y = 42 336 432 1728 540 1080 420 p = 1 p = 5 p = 10 p = 70 p = 490 y = 42 336 432 1728 540 1080 420 490 p = 1 p = 7 p = 56 p = 280 p = 2520 y = 42 336 432 1728 540 1080 420 490 2520

3   Pass
filetext = fileread('ProdMat.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

4   Pass
filetext = fileread('ProdMat.m'); assert(isempty(strfind(filetext, 'prod')),'prod() function is forbidden')

5   Pass
filetext = fileread('ProdMat.m'); assert(isempty(strfind(filetext, '!echo')),'!echo hacks are forbidden')