Cody

# Problem 722. Make a run-length companion vector

Solution 1313794

Submitted on 25 Oct 2017 by Eric G.
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))

r = 1 r = 1 1 r = 1 1 2 r = 1 1 2 1 r = 1 1 2 1 1 r = 1 1 2 1 1 1 r = 1 1 2 1 1 1 2 r = 1 1 2 1 1 1 2 1 r = 1 1 2 1 1 1 2 1 2 r = 1 1 2 1 1 1 2 1 2 3 r = 1 1 2 1 1 1 2 1 2 3 4 r = 1 1 2 1 1 1 2 1 2 3 4 1 r = 1 1 2 1 1 1 2 1 2 3 4 1 1 r = 1 1 2 1 1 1 2 1 2 3 4 1 1 1 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))

r = 1 r = 1 2 r = 1 2 3 r = 1 2 3 4 r = 1 2 3 4 5 r = 1 2 3 4 5 6 r = 1 2 3 4 5 6 7 r = 1 2 3 4 5 6 7 8 r = 1 2 3 4 5 6 7 8 9 r = 1 2 3 4 5 6 7 8 9 10 r = 1 2 3 4 5 6 7 8 9 10 11 r = 1 2 3 4 5 6 7 8 9 10 11 12 r = 1 2 3 4 5 6 7 8 9 10 11 12 13 r = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 r = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 r = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 r = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 r = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 r = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 r = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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))

r = 1 r = 1 2 r = 1 2 3 r = 1 2 3 1 r = 1 2 3 1 2 r = 1 2 3 1 2 1 r = 1 2 3 1 2 1 1 r = 1 2 3 1 2 1 1 2 r = 1 2 3 1 2 1 1 2 1 r = 1 2 3 1 2 1 1 2 1 2 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))

r = 1 r = 1 1 r = 1 1 1 r = 1 1 1 1 r = 1 1 1 1 1 r = 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 r = 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 r = 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 r = 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 r = 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 r = 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 r = Columns 1 through 29 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 Column 30 1 r = Columns 1 through 29 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 30 through 31 1 1 r = Columns 1 through 29 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 30 through 32 1 1 1 r = Columns 1 through 29 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 30 through 33 1 1 1 1 r = Columns 1 through 29 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 30 through 34 1 1 1 1 1 r = Columns 1 through 29 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 30 through 35 1 1 1 1 1 1 r = Columns 1 through 29 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 30 through 36 1 1 1 1 1 1 1 r = Columns 1 through 29 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 30 through 37 1 1 1 1 1 1 1 1 r = Columns 1 through 29 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 30 through 38 1 1 1 1 1 1 1 1 1 r = Columns 1 through 29 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 30 through 39 1 1 1 1 1 1 1 1 1 1 r = Columns 1 through 29 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 30 through 40 1 1 1 1 1 1 1 1 1 1 1

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

r = 1 r = 1 1 r = 1 1 2 r = 1 1 2 3 r = 1 1 2 3 4 r = 1 1 2 3 4 5 r = 1 1 2 3 4 5 6 r = 1 1 2 3 4 5 6 7 r = 1 1 2 3 4 5 6 7 8 r = 1 1 2 3 4 5 6 7 8 9 r = 1 1 2 3 4 5 6 7 8 9 10 r = 1 1 2 3 4 5 6 7 8 9 10 11 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 r = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Column 30 29 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 31 29 30 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 32 29 30 31 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 33 29 30 31 32 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 34 29 30 31 32 33 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 35 29 30 31 32 33 34 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 36 29 30 31 32 33 34 35 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 37 29 30 31 32 33 34 35 36 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 38 29 30 31 32 33 34 35 36 37 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 39 29 30 31 32 33 34 35 36 37 38 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 40 29 30 31 32 33 34 35 36 37 38 39 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 41 29 30 31 32 33 34 35 36 37 38 39 40 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 42 29 30 31 32 33 34 35 36 37 38 39 40 41 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 43 29 30 31 32 33 34 35 36 37 38 39 40 41 42 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 44 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 45 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 46 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 47 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 48 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 49 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 50 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 51 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 52 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 r = Columns 1 through 29 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20...