Cody

Problem 2672. Largest Geometric Series

Solution 3080391

Submitted on 6 Oct 2020
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
a = 2*3.^(1:3); b = 3*4.^(0:5); vec = [a b]; output = b; test = gSeries(vec); assert(isequal(test,output));

a = 4 b = 5 c = logical 1 d = 4 ans = 3 12 48 192 768 3072

2   Pass
a = ones(1,50); b = 3*4.^(1:5); vec = [a b]; output = a; test = gSeries(vec); assert(isequal(test,output));

a = 1 b = 49 c = logical 1 d = 1 ans = Columns 1 through 29 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 1 1 1 1 Columns 30 through 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

3   Fail
a = ones(1,50); b = randi(5,[1 10]); p = randperm(60); vec = [a b]; vec = vec(p); output = nonzeros(vec==1)'; test = gSeries(vec); assert(isequal(test,output));

a = 1 b = 46 c = logical 1 d = 1 ans = Columns 1 through 29 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 1 1 1 5 1 1 1 1 Columns 30 through 47 1 1 3 5 1 1 1 1 1 1 1 1 1 1 1 1 2 1

Assertion failed.

4   Fail
a = 2.^(1:15); b = 3.^(1:10); c = 5.^(1:10); vec = [a b c]; p = randperm(35); vec = vec(p); output = a; test = gSeries(vec); assert(isequal(test,output));

a = 6.7740e-05 b = 1 c = logical 1 d = 12 ans = 59049 4

Assertion failed.

5   Fail
a = 2*3.^(1:10); vec = [a a]; p = randperm(20); vec = vec(p); output = a; test = gSeries(vec); assert(isequal(test,output));

a = 0.0370 b = 4 c = logical 1 d = 2 ans = 4374 162 6 54 13122

Assertion failed.

Suggested Problems

More from this Author44

Community Treasure Hunt

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

Start Hunting!