Cody

# Problem 722. Make a run-length companion vector

Solution 673977

Submitted on 22 May 2015 by M_Morelock
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 = [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))

counter = 2 r = 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 counter = 2 r = 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 counter = 2 r = 1 1 2 1 1 1 2 1 2 1 1 1 1 1 1 counter = 3 r = 1 1 2 1 1 1 2 1 2 3 1 1 1 1 1 counter = 4 r = 1 1 2 1 1 1 2 1 2 3 4 1 1 1 1 counter = 2 r = 1 1 2 1 1 1 2 1 2 3 4 1 1 1 2

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

counter = 2 r = Columns 1 through 16 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 3 r = Columns 1 through 16 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 4 r = Columns 1 through 16 1 2 3 4 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 5 r = Columns 1 through 16 1 2 3 4 5 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 6 r = Columns 1 through 16 1 2 3 4 5 6 1 1 1 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 7 r = Columns 1 through 16 1 2 3 4 5 6 7 1 1 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 8 r = Columns 1 through 16 1 2 3 4 5 6 7 8 1 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 9 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 10 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 11 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 1 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 12 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 1 1 1 1 Columns 17 through 20 1 1 1 1 counter = 13 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 1 1 1 Columns 17 through 20 1 1 1 1 counter = 14 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 1 Columns 17 through 20 1 1 1 1 counter = 15 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 Columns 17 through 20 1 1 1 1 counter = 16 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 20 1 1 1 1 counter = 17 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 20 17 1 1 1 counter = 18 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 20 17 18 1 1 counter = 19 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 20 17 18 19 1 counter = 20 r = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 20 17 18 19 20

3   Pass
%% 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))

counter = 2 r = 1 2 1 1 1 1 1 1 1 1 1 counter = 3 r = 1 2 3 1 1 1 1 1 1 1 1 counter = 2 r = 1 2 3 1 2 1 1 1 1 1 1 counter = 2 r = 1 2 3 1 2 1 1 2 1 1 1 counter = 2 r = 1 2 3 1 2 1 1 2 1 2 1 counter = 3 r = 1 2 3 1 2 1 1 2 1 2 3

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

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

counter = 2 r = Columns 1 through 16 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 3 r = Columns 1 through 16 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 4 r = Columns 1 through 16 1 1 2 3 4 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 5 r = Columns 1 through 16 1 1 2 3 4 5 1 1 1 1 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 6 r = Columns 1 through 16 1 1 2 3 4 5 6 1 1 1 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 7 r = Columns 1 through 16 1 1 2 3 4 5 6 7 1 1 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 8 r = Columns 1 through 16 1 1 2 3 4 5 6 7 8 1 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 9 r = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 10 r = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 11 r = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 12 r = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 13 r = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 101 1 1 1 1 1 counter = 14 r = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...