Cody

# Problem 43219. Modified run-length companion vector

Solution 1039279

Submitted on 31 Oct 2016 by Joselito Flores
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 2 2 1 2]; assert(isequal(run_length(x),r_correct)) 2

z = 1 y = 1 z = 2 y = 1 1 z = 2 3 y = 1 1 2 z = 4 y = 1 1 2 1 z = 5 y = 1 1 2 1 1 z = 6 y = 1 1 2 1 1 1 z = 6 7 y = 1 1 2 1 1 1 2 z = 8 y = 1 1 2 1 1 1 2 1 z = 8 9 y = 1 1 2 1 1 1 2 1 2 z = 8 9 10 y = 1 1 2 1 1 1 2 1 2 3 z = 8 9 10 11 y = 1 1 2 1 1 1 2 1 2 3 4 z = 1 12 y = 1 1 2 1 1 1 2 1 2 3 4 2 z = 4 13 y = 1 1 2 1 1 1 2 1 2 3 4 2 2 z = 14 y = 1 1 2 1 1 1 2 1 2 3 4 2 2 1 z = 14 15 y = 1 1 2 1 1 1 2 1 2 3 4 2 2 1 2 ans = 2

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

z = 1 y = 1 z = 1 2 y = 1 2 z = 1 2 3 y = 1 2 3 z = 1 2 3 4 y = 1 2 3 4 z = 1 2 3 4 5 y = 1 2 3 4 5 z = 1 2 3 4 5 6 y = 1 2 3 4 5 6 z = 1 2 3 4 5 6 7 y = 1 2 3 4 5 6 7 z = 1 2 3 4 5 6 7 8 y = 1 2 3 4 5 6 7 8 z = 1 2 3 4 5 6 7 8 9 y = 1 2 3 4 5 6 7 8 9 z = 1 2 3 4 5 6 7 8 9 10 y = 1 2 3 4 5 6 7 8 9 10 z = 1 2 3 4 5 6 7 8 9 10 11 y = 1 2 3 4 5 6 7 8 9 10 11 z = 1 2 3 4 5 6 7 8 9 10 11 12 y = 1 2 3 4 5 6 7 8 9 10 11 12 z = 1 2 3 4 5 6 7 8 9 10 11 12 13 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 z = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 z = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 z = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 y = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 z = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Column 17 17 y = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Column 17 17 z = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 18 17 18 y = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 18 17 18 z = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 19 17 18 19 y = Columns 1 through 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Columns 17 through 19 17 18 19 z = 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 y = 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 ans = 3

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

z = 1 y = 1 z = 1 2 y = 1 2 z = 1 2 3 y = 1 2 3 z = 4 y = 1 2 3 1 z = 4 5 y = 1 2 3 1 2 z = 6 y = 1 2 3 1 2 1 z = 7 y = 1 2 3 1 2 1 1 z = 7 8 y = 1 2 3 1 2 1 1 2 z = 9 y = 1 2 3 1 2 1 1 2 1 z = 9 10 y = 1 2 3 1 2 1 1 2 1 2 z = 9 10 11 y = 1 2 3 1 2 1 1 2 1 2 3 ans = 4

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

z = 1 y = 1 z = 2 y = 1 1 z = 3 y = 1 1 1 z = 4 y = 1 1 1 1 z = 5 y = 1 1 1 1 1 z = 6 y = 1 1 1 1 1 1 z = 7 y = 1 1 1 1 1 1 1 z = 8 y = 1 1 1 1 1 1 1 1 z = 9 y = 1 1 1 1 1 1 1 1 1 z = 10 y = 1 1 1 1 1 1 1 1 1 1 z = 11 y = 1 1 1 1 1 1 1 1 1 1 1 z = 12 y = 1 1 1 1 1 1 1 1 1 1 1 1 z = 13 y = 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 14 y = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 15 y = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 16 y = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 17 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Column 17 1 z = 18 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 18 1 1 z = 19 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 19 1 1 1 z = 20 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 20 1 1 1 1 z = 21 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 21 1 1 1 1 1 z = 22 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 22 1 1 1 1 1 1 z = 23 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 23 1 1 1 1 1 1 1 z = 24 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 24 1 1 1 1 1 1 1 1 z = 25 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 25 1 1 1 1 1 1 1 1 1 z = 26 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 26 1 1 1 1 1 1 1 1 1 1 z = 27 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 27 1 1 1 1 1 1 1 1 1 1 1 z = 28 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 28 1 1 1 1 1 1 1 1 1 1 1 1 z = 29 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 29 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 30 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 30 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 31 y = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 31 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 z = 32 y = Columns 1 through 16 1 1 1 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 z = 33 y = Columns 1 through 16 1 1 1 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 Column 33 1 z = 34 y = Columns 1 through 16 1 1 1 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 34 1 1 z = 35 y = Columns 1 through 16 1 1 1 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 35 1 1 1 z = 36 y = Columns 1 through 16 1 1 1 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 36 1 1 1 1 z = 37 y = Columns 1 through 16 1 1 1 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 37 1 1 1 1 1 z = 38 y = Columns 1 through 16 1 1 1 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 38 1 1 1 1 1 1 z = 39 y = Columns 1 through 16 1 1 1 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 39 1 1 1 1 1 1 1 z = 40 y = Columns 1 through 16 1 1 1 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 40 1 1 1 1 1 1 1 1 ans = 5

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

z = 1 y = 1 z = 2 y = 1 1 z = 2 3 y = 1 1 2 z = 2 3 4 y = 1 1 2 3 z = 2 3 4 5 y = 1 1 2 3 4 z = 2 3 4 5 6 y = 1 1 2 3 4 5 z = 2 3 4 5 6 7 y = 1 1 2 3 4 5 6 z = 2 3 4 5 6 7 8 y = 1 1 2 3 4 5 6 7 z = 2 3 4 5 6 7 8 9 y = 1 1 2 3 4 5 6 7 8 z = 2 3 4 5 6 7 8 9 10 y = 1 1 2 3 4 5 6 7 8 9 z = 2 3 4 5 6 7 8 9 10 11 y = 1 1 2 3 4 5 6 7 8 9 10 z = 2 3 4 5 6 7 8 9 10 11 12 y = 1 1 2 3 4 5 6 7 8 9 10 11 z = 2 3 4 5 6 7 8 9 10 11 12 13 y = 1 1 2 3 4 5 6 7 8 9 10 11 12 z = 2 3 4 5 6 7 8 9 10 11 12 13 14 y = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 z = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 y = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 z = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 y = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 z = 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Column 17 16 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Column 17 18 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 18 16 17 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 18 18 19 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 19 16 17 18 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 19 18 19 20 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 20 16 17 18 19 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 20 18 19 20 21 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 21 16 17 18 19 20 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 21 18 19 20 21 22 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 22 16 17 18 19 20 21 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 22 18 19 20 21 22 23 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 23 16 17 18 19 20 21 22 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 23 18 19 20 21 22 23 24 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 24 16 17 18 19 20 21 22 23 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 24 18 19 20 21 22 23 24 25 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 25 16 17 18 19 20 21 22 23 24 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 25 18 19 20 21 22 23 24 25 26 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 26 16 17 18 19 20 21 22 23 24 25 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 26 18 19 20 21 22 23 24 25 26 27 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 27 16 17 18 19 20 21 22 23 24 25 26 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 27 18 19 20 21 22 23 24 25 26 27 28 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 28 16 17 18 19 20 21 22 23 24 25 26 27 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 28 18 19 20 21 22 23 24 25 26 27 28 29 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 29 16 17 18 19 20 21 22 23 24 25 26 27 28 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 29 18 19 20 21 22 23 24 25 26 27 28 29 30 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 30 16 17 18 19 20 21 22 23 24 25 26 27 28 29 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 30 18 19 20 21 22 23 24 25 26 27 28 29 30 31 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 31 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 31 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 32 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 32 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 32 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Column 33 32 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 32 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Column 33 34 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 32 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Columns 33 through 34 32 33 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Columns 17 through 32 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Columns 33 through 34 34 35 y = Columns 1 through 16 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Columns 17 through 32 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Columns 33 through 35 32 33 34 z = Columns 1 through 16 2 3 4 5 6 7 8 9 10 11 12 13 14 ...