Cody

# Problem 722. Make a run-length companion vector

Solution 1925595

Submitted on 8 Sep 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 = [5 3 3 1 0 9 9 4 4 4 4 5 1 2 2]; r_correct = [1 1 2 1 1 1 2 1 2 3 4 1 1 1 2]; assert(isequal(run_length(x),r_correct))

k = 2 k = 2 r = 1 1 2 1 1 1 0 1 0 0 0 1 1 1 0 k = 2 k = 2 k = 2 r = 1 1 2 1 1 1 2 1 0 0 0 1 1 1 0 k = 2 r = 1 1 2 1 1 1 2 1 2 0 0 1 1 1 0 r = 1 1 2 1 1 1 2 1 2 2 0 1 1 1 0 r = 1 1 2 1 1 1 2 1 2 2 2 1 1 1 0 k = 2 k = 2 k = 2 r = 1 1 2 1 1 1 2 1 2 2 2 1 1 1 2 r = 1 1 2 1 1 1 2 1 2 2 2 1 1 1 2

Assertion failed.

2   Fail
x = ones(1,20); r_correct = 1:20; assert(isequal(run_length(x),r_correct))

k = 2 r = 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 r = 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

Assertion failed.

3   Fail
x = [1 1 1 2 2 3 4 4 5 5 5]; r_correct = [1 2 3 1 2 1 1 2 1 2 3]; assert(isequal(run_length(x),r_correct))

k = 2 r = 1 2 0 1 0 1 1 0 1 0 0 r = 1 2 2 1 0 1 1 0 1 0 0 k = 2 r = 1 2 2 1 2 1 1 0 1 0 0 k = 2 k = 2 r = 1 2 2 1 2 1 1 2 1 0 0 k = 2 r = 1 2 2 1 2 1 1 2 1 2 0 r = 1 2 2 1 2 1 1 2 1 2 2 r = 1 2 2 1 2 1 1 2 1 2 2

Assertion failed.

4   Pass
x = 1:40; r_correct = ones(size(x)); assert(isequal(run_length(x),r_correct))

k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 k = 2 r = Columns 1 through 30 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 31 through 40 1 1 1 1 1 1 1 1 1 1

5   Fail
x = [-34 -17*ones(1,100)]; r_correct = [1 1:100]; assert(isequal(run_length(x),r_correct))

k = 2 k = 2 r = Columns 1 through 30 1 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 91 through 101 0 0 0 0 0 0 0 0 0 0 0 r = Columns 1 through 30 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 31 through 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

Assertion failed.