Cody

Problem 44467. Product of Each Column

Solution 1451574

Submitted on 27 Feb 2018 by shimon zusmanovsky
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 = [] x = 1 x = 1 x = 1 x = 1 x = 1 x = 1 v = 1 x = 1 x = 1 x = 1 x = 1 x = 1 x = 1 v = 1 1 x = 1 x = 1 x = 1 x = 1 x = 1 x = 1 v = 1 1 1 x = 1 x = 1 x = 1 x = 1 x = 1 x = 1 v = 1 1 1 1 x = 1 x = 1 x = 1 x = 1 x = 1 x = 1 v = 1 1 1 1 1 x = 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 = [] x = 1 x = 1 x = 5 x = 10 v = 10 x = 1 x = 2 x = 12 x = 36 v = 10 36 x = 1 x = 3 x = 21 x = 84 v = 10 36 84 x = 1 x = 4 x = 8 x = 40 v = 10 36 84 40 x = 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 = 7 n = 11 v = [] x = 1 x = 1 x = 4 x = 20 x = 40 x = 40 x = 200 x = 600 v = 600 x = 1 x = 3 x = 6 x = 24 x = 72 x = 72 x = 216 x = 216 v = 600 216 x = 1 x = 3 x = 3 x = 15 x = 60 x = 300 x = 900 x = 2700 v = 600 216 2700 x = 1 x = 5 x = 10 x = 20 x = 40 x = 40 x = 40 x = 160 v = 600 216 2700 160 x = 1 x = 4 x = 8 x = 16 x = 48 x = 240 x = 480 x = 1920 v = 600 216 2700 160 1920 x = 1 x = 2 x = 2 x = 4 x = 8 x = 8 x = 40 x = 80 v = 600 216 2700 160 1920 80 x = 1 x = 1 x = 4 x = 4 x = 16 x = 16 x = 64 x = 128 v = 600 216 2700 160 1920 80 128 x = 1 x = 1 x = 4 x = 4 x = 4 x = 12 x = 36 x = 72 v = 600 216 2700 160 1920 80 128 72 x = 1 x = 5 x = 15 x = 30 x = 120 x = 600 x = 600 x = 2400 v = 600 216 2700 160 1920 80 128 72 2400 x = 1 x = 1 x = 3 x = 12 x = 36 x = 108 x = 216 x = 864 v = 600 216 2700 160 1920 80 128 72 2400 864 x = 1 x = 5 x = 15 x = 45 x = 135 x = 540 x = 1080 x = 4320 v = 600 216 2700 160 1920 80 128 72 2400 864 4320 x = 1

Community Treasure Hunt

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

Start Hunting!