Cody

# Problem 722. Make a run-length companion vector

Solution 512401

Submitted on 14 Oct 2014 by Aslak Grinsted
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 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 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 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 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 = 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 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 Column 31 1 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 32 1 1 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 33 1 1 1 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 34 1 1 1 1 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 35 1 1 1 1 1 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 36 1 1 1 1 1 1 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 37 1 1 1 1 1 1 1 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 38 1 1 1 1 1 1 1 1 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 39 1 1 1 1 1 1 1 1 1 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   Pass
%% x = [-34 -17*ones(1,100)]; r_correct = [1 1:100]; assert(isequal(run_length(x),r_correct))

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 = 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 29 r = Columns 1 through 30 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 29 Column 31 30 r = Columns 1 through 30 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 29 Columns 31 through 32 30 31 r = Columns 1 through 30 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 29 Columns 31 through 33 30 31 32 r = Columns 1 through 30 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 29 Columns 31 through 34 30 31 32 33 r = Columns 1 through 30 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 29 Columns 31 through 35 30 31 32 33 34 r = Columns 1 through 30 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 29 Columns 31 through 36 30 31 32 33 34 35 r = Columns 1 through 30 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 29 Columns 31 through 37 30 31 32 33 34 35 36 r = Columns 1 through 30 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 29 Columns 31 through 38 30 31 32 33 34 35 36 37 r = Columns 1 through 30 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 29 Columns 31 through 39 30 31 32 33 34 35 36 37 38 r = Columns 1 through 30 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 29 Columns 31 through 40 30 31 32 33 34 35 36 37 38 39 r = Columns 1 through 30 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 29 Columns 31 through 41 30 31 32 33 34 35 36 37 38 39 40 r = Columns 1 through 30 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 29 Columns 31 through 42 30 31 32 33 34 35 36 37 38 39 40 41 r = Columns 1 through 30 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 29 Columns 31 through 43 30 31 32 33 34 35 36 37 38 39 40 41 42 r = Columns 1 through 30 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 29 Columns 31 through 44 30 31 32 33 34 35 36 37 38 39 40 41 42 43 r = Columns 1 through 30 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 29 Columns 31 through 45 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 r = Columns 1 through 30 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 29 Columns 31 through 46 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 r = Columns 1 through 30 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 29 Columns 31 through 47 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 r = Columns 1 through 30 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 29 Columns 31 through 48 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 r = Columns 1 through 30 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 29 Columns 31 through 49 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 r = Columns 1 through 30 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 29 Columns 31 through 50 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 r = Columns 1 through 30 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 29 Columns 31 through 51 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 30 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 29 Columns 31 through 52 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 30 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 29 Columns 31 through 53 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 r = Columns 1 through 30 1 1 2 3 4 5 ...

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!