Cody

Problem 112. Remove the air bubbles

Solution 1536273

Submitted on 22 May 2018 by reema ziada
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 = [ 1 2 3 0 4 5 6 0 0 ]; b_correct = [ 0 0 0 1 2 3 6 4 5 ]; assert(isequal(bubbles(a),b_correct))

v = 1 0 6 z = 3×1 logical array 0 1 0 x = 2 nz = 3×1 logical array 1 0 1 x = 1 3 ans = 1 6 v = 2 4 0 z = 3×1 logical array 0 0 1 x = 3 nz = 3×1 logical array 1 1 0 x = 1 2 ans = 2 4 v = 3 5 0 z = 3×1 logical array 0 0 1 x = 3 nz = 3×1 logical array 1 1 0 x = 1 2 ans = 3 5

2   Pass
a = [ 1 0 5 0 7 0 6 ]'; b_correct = [ 0 0 0 1 5 7 6 ]'; assert(isequal(bubbles(a),b_correct))

v = 1 0 5 0 7 0 6 z = 7×1 logical array 0 1 0 1 0 1 0 x = 2 4 6 nz = 7×1 logical array 1 0 1 0 1 0 1 x = 1 3 5 7 ans = 1 5 7 6

3   Pass
a = [1 0; 1 1]; b_correct = [1 0; 1 1]; assert(isequal(bubbles(a),b_correct))

v = 1 1 z = 2×1 logical array 0 0 x = 0×1 empty double column vector nz = 2×1 logical array 1 1 x = 1 2 ans = 1 1 v = 0 1 z = 2×1 logical array 1 0 x = 1 nz = 2×1 logical array 0 1 x = 2 ans = 1

4   Pass
a = [0 8 0 6 -2]'; b_correct = [0 0 8 6 -2]'; assert(isequal(bubbles(a),b_correct))

v = 0 8 0 6 -2 z = 5×1 logical array 1 0 1 0 0 x = 1 3 nz = 5×1 logical array 0 1 0 1 1 x = 2 4 5 ans = 8 6 -2