Cody

# Problem 44901. Rearrange the given matrix to have all its zeros climb up to the top of each column - using for loops.

Solution 1860128

Submitted on 28 Jun 2019 by kashish sharma
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
x = [0 0 1 1 0 1 -1 -1 2 1 -1 2 2 2 0 0 -1 0 2 1 0 1 0 1]; y_correct = [0 0 0 0 0 0 0 1 0 1 1 -1 2 1 -1 2 2 2 -1 1 -1 1 2 1]; assert(isequal(zerosFirst(x),y_correct))

a = 6 4 b = 1 b = 1 2 c = 3 c = 3 4 c = 3 4 5 b = 1 2 6 d = 1 2 6 3 4 5 b = 1 c = 2 c = 2 3 c = 2 3 4 b = 1 5 c = 2 3 4 6 d = 1 5 2 3 4 6 c = 1 c = 1 2 c = 1 2 3 b = 4 c = 1 2 3 5 b = 4 6 d = 4 6 1 2 3 5 c = 1 c = 1 2 c = 1 2 3 b = 4 c = 1 2 3 5 c = 1 2 3 5 6 d = 4 1 2 3 5 6

2   Pass
x = [12 56 0 0 65 122 0 37]' y_correct = [0 0 0 12 56 65 122 37]' assert(isequal(zerosFirst(x),y_correct))

x = 12 56 0 0 65 122 0 37 y_correct = 0 0 0 12 56 65 122 37 a = 8 1 c = 1 c = 1 2 b = 3 b = 3 4 c = 1 2 5 c = 1 2 5 6 b = 3 4 7 c = 1 2 5 6 8 d = 3 4 7 1 2 5 6 8

3   Pass
filetext = fileread('zerosFirst.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

4   Pass
filetext = fileread('zerosFirst.m'); assert(~isempty(strfind(filetext, 'for')),'must use a for loop in solving this problem')

5   Pass
filetext = fileread('zerosFirst.m'); assert(isempty(strfind(filetext, '!echo')),'!echo hacks are forbidden')