Cody

Problem 44467. Product of Each Column

Solution 2075585

Submitted on 31 Dec 2019 by IDAN ASULIN
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 v = 1 1 1 1 1 v = 1 1 1 1 1 v = 1 1 1 1 1 v = 1 1 1 1 1 v = 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)))

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

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 = 12 n = 15 v = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 v = 3 1 1 2 5 1 2 3 2 3 1 4 1 4 2 v = 6 5 2 2 25 3 4 15 4 3 2 20 5 20 6 v = 30 20 4 10 25 6 12 15 16 6 4 80 25 20 12 v = 120 20 16 20 50 30 48 60 64 6 16 320 25 80 12 v = Columns 1 through 14 600 40 48 40 50 150 144 60 128 24 80 1280 25 160 Column 15 24 v = Columns 1 through 14 600 40 240 200 50 600 288 60 256 120 320 2560 100 160 Column 15 24 v = Columns 1 through 14 1800 120 480 1000 250 600 1152 60 1024 600 960 7680 500 480 Column 15 48 v = Columns 1 through 14 7200 600 480 1000 500 600 1152 300 2048 1800 3840 7680 2500 1920 Column 15 144 v = Columns 1 through 14 14400 1200 1920 4000 500 3000 2304 900 4096 5400 11520 23040 2500 3840 Column 15 432 v = Columns 1 through 14 28800 6000 9600 20000 2500 12000 9216 900 16384 10800 57600 115200 5000 15360 Column 15 864 v = Columns 1 through 14 57600 12000 38400 20000 10000 48000 18432 1800 81920 32400 230400 115200 10000 46080 Column 15 864 v = Columns 1 through 14 288000 24000 115200 60000 40000 144000 55296 9000 409600 97200 691200 230400 20000 184320 Column 15 2592

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!