Cody

# Problem 2672. Largest Geometric Series

Solution 3117381

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

y = 6.0000 3.0000 1.5000 0.7500 0.3750 0.1875 0.0938 0.0469 0.0234

Assertion failed.

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

Index exceeds the number of array elements (6). Error in gSeries (line 10) m = temp2(i); Error in Test2 (line 5) test = gSeries(vec);

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

Index exceeds the number of array elements (4). Error in gSeries (line 10) m = temp2(i); Error in Test3 (line 7) test = gSeries(vec);

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

y = Columns 1 through 17 243.0000 2.0000 0.0165 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 Columns 18 through 34 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 Column 35 0.0000

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

Index exceeds the number of array elements (10). Error in gSeries (line 10) m = temp2(i); Error in Test5 (line 6) test = gSeries(vec);

### Community Treasure Hunt

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

Start Hunting!