Cody

Problem 44467. Product of Each Column

Solution 2541624

Submitted on 13 Jun 2020 by Shahar Kalfon
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))

m = 5 n = 5 double = 1 double = 1 double = 1 double = 1 double = 1 v = 1 double = 1 double = 1 double = 1 double = 1 double = 1 double = 1 v = 1 1 double = 1 double = 1 double = 1 double = 1 double = 1 double = 1 v = 1 1 1 double = 1 double = 1 double = 1 double = 1 double = 1 double = 1 v = 1 1 1 1 double = 1 double = 1 double = 1 double = 1 double = 1 double = 1 v = 1 1 1 1 1 double = 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)))

m = 3 n = 4 double = 1 double = 5 double = 10 v = 10 double = 1 double = 2 double = 12 double = 36 v = 10 36 double = 1 double = 3 double = 21 double = 84 v = 10 36 84 double = 1 double = 4 double = 8 double = 40 v = 10 36 84 40 double = 1

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)))

m = 10 n = 10 double = 4 double = 8 double = 40 double = 40 double = 200 double = 600 double = 1800 double = 9000 double = 18000 double = 54000 v = 54000 double = 1 double = 2 double = 2 double = 6 double = 12 double = 24 double = 48 double = 96 double = 288 double = 1440 double = 4320 v = 54000 4320 double = 1 double = 1 double = 5 double = 25 double = 50 double = 50 double = 150 double = 450 double = 900 double = 2700 double = 5400 v = 54000 4320 5400 double = 1 double = 5 double = 10 double = 20 double = 20 double = 80 double = 320 double = 960 double = 2880 double = 11520 double = 23040 v = 54000 4320 5400 23040 double = 1 double = 4 double = 16 double = 48 double = 192 double = 192 double = 960 double = 960 double = 3840 double = 3840 double = 7680 v = 54000 4320 5400 23040 7680 double = 1 double = 5 double = 10 double = 50 double = 150 double = 150 double = 150 double = 150 double = 300 double = 900 double = 1800 v = 54000 4320 5400 23040 7680 1800 double = 1 double = 3 double = 6 double = 12 double = 36 double = 144 double = 288 double = 1440 double = 5760 double = 11520 double = 57600 v = 54000 4320 5400 23040 7680 1800 57600 double = 1 double = 2 double = 4 double = 8 double = 16 double = 64 double = 192 double = 192 double = 576 double = 576 double = 1728 v = 54000 4320 5400 23040 7680 1800 57600 1728 double = 1 double = 5 double = 10 double = 40 double = 40 double = 160 double = 160 double = 320 double = 320 double = 960 double = 4800 v = 54000 4320 5400 23040 7680 1800 57600 1728 4800 double = 1 double = 5 double = 20 double = 20 double = 40 double = 40 double = 160 double = 160 double = 480 double = 1920 double = 1920 v = 54000 4320 5400 23040 7680 1800 57600 1728 4800 1920 double = 1

Suggested Problems

More from this Author25

Community Treasure Hunt

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

Start Hunting!