Cody

Problem 722. Make a run-length companion vector

Solution 2749681

Submitted on 28 Jul 2020 by Raghunadh N
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))

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

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

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

z = 1 1 2 z = 1 1 2 3 z = 1 1 2 3 4 z = 1 1 2 3 4 5 z = 1 1 2 3 4 5 6 z = 1 1 2 3 4 5 6 7 z = 1 1 2 3 4 5 6 7 8 z = 1 1 2 3 4 5 6 7 8 9 z = 1 1 2 3 4 5 6 7 8 9 10 z = 1 1 2 3 4 5 6 7 8 9 10 11 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 z = 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 z = 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 ...