Cody

# Problem 1898. Too Many Zeros, Dump Them!

Solution 1888017

Submitted on 30 Jul 2019
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
x = 0; y_correct = []; assert(isequal(ZeroDumping(x),y_correct))

a = 0×1 empty double column vector

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in ZeroDumping (line 3) if any(a(i,:))==0 Error in Test1 (line 3) assert(isequal(ZeroDumping(x),y_correct))

2   Fail
x = 1; y_correct = 1; assert(isequal(ZeroDumping(x),y_correct))

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in ZeroDumping (line 3) if any(a(i,:))==0 Error in Test2 (line 3) assert(isequal(ZeroDumping(x),y_correct))

3   Fail
x = [1 0]; y_correct = 1; assert(isequal(ZeroDumping(x),y_correct))

Index in position 1 is invalid. Array indices must be positive integers or logical values. Error in ZeroDumping (line 3) if any(a(i,:))==0 Error in Test3 (line 3) assert(isequal(ZeroDumping(x),y_correct))

4   Fail
x = [1 0 1 0; 0 0 1 0]; y_correct = [1 0 1 0 0 1]; assert(isequal(ZeroDumping(x),y_correct));

a = 1 0 1 0 0 1 a = 1 1 0 1 b = 1 1 0 1

Assertion failed.

5   Pass
x=[1,0, -3, 1i,0; 2,0.3,2i, 0, 0; 0,0, 0, inf, 0; 0,0, 0, 0, 1]; y_correct =x;% x(4,5) is useful, I don't want to dump it. assert(isequal(ZeroDumping(x),y_correct));

b = 1.0000 + 0.0000i 0.0000 + 0.0000i -3.0000 + 0.0000i 0.0000 + 1.0000i 0.0000 + 0.0000i 2.0000 + 0.0000i 0.3000 + 0.0000i 0.0000 + 2.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i Inf + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i

6   Fail
x =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 eps]; y_correct =x; assert(isequal(ZeroDumping(x),y_correct));

a = 1.0e-15 * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2220 a = 1.0e-15 * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.2220 a = 1.0e-15 * 0 0 0 0 0 0 0 0 0 0 0 0.2220 b = 1.0e-15 * 0 0 0 0 0 0 0 0 0 0 0 0.2220

Assertion failed.

7   Fail
x =[1 1 0 0 0 1 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0]; y_correct =[1 1 0 0 1 0 0 0 0 0 0 3]; assert(isequal(ZeroDumping(x),y_correct));

a = 1 1 0 0 0 1 0 0 0 0 0 0 0 3 0 0 0 0 0 0 a = 1 1 0 0 0 1 0 0 0 0 0 0 0 3 0 a = 1 1 0 0 1 0 0 0 0 0 0 3 a = 1 1 0 1 0 0 0 0 3 b = 1 1 0 1 0 0 0 0 3

Assertion failed.

8   Fail
x =[1 1 0 0 0 1 0 0 0 0 0 0 0 3 0 0 0 0 0 inf 0 0 0 0 0]; y_correct =[1 1 0 0 0 1 0 0 0 0 0 0 0 3 0 0 0 0 0 inf]; assert(isequal(ZeroDumping(x),y_correct));

a = 1 1 0 0 0 1 0 0 0 0 0 0 0 3 0 0 0 0 0 Inf a = 1 1 0 0 1 0 0 0 0 0 3 0 0 0 0 Inf b = 1 1 0 0 1 0 0 0 0 0 3 0 0 0 0 Inf

Assertion failed.