Cody

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

Solution 1835043

Submitted on 2 Jun 2019 by Avishay Hertz
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))

h = 0 h = 0 h = 2 h = 2 h = -1 h = 0 j = 2 h = 0 h = 1 h = 1 h = 2 h = 0 h = 1 j = 3 h = 1 h = -1 h = -1 h = 0 h = 2 h = 0 j = 4 h = 1 h = -1 h = 2 h = 0 h = 1 h = 1 j = 5 0 0 1 1 0 1 -1 -1 2 1 -1 2 2 2 0 0 -1 0 2 1 0 1 0 1 0 0 0 0 0 0 0 1 0 1 1 -1 2 1 -1 2 2 2 -1 1 -1 1 2 1

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 h = 12 h = 56 h = 0 h = 0 h = 65 h = 122 h = 0 h = 37 j = 2 12 56 0 0 65 122 0 37 0 0 0 12 56 65 122 37

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