Cody

# Problem 672. Longest run of consecutive numbers

Solution 101618

Submitted on 22 Jun 2012
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
%% a = [1 2 2 2 1 3 2 1 4 5 1]; y_correct = 2; assert(isequal(longrun(a),y_correct))

counter = 0 counter = 1 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 counter = 2 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 counter = 3 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 0 counter = 4 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 0 0 counter = 5 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 0 0 0 counter = 6 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 0 0 0 0 counter = 7 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 0 0 0 0 0 counter = 8 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 0 0 0 0 0 0 counter = 9 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 0 0 0 0 0 0 0 counter = 10 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = 0 0 0 0 0 0 0 0 0 0 counter = 11 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 g = 1 5 8 11 notg = 2 3 4 6 7 9 10 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 b = Columns 1 through 10 1 0 0 0 1 0 0 1 0 0 Column 11 1 s = 10001001001 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Column 11 1 counter = 12 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 g = 2 3 4 7 notg = 1 5 6 8 9 10 11 b = Columns 1 through 10 1 1 1 1 1 3 1 1 4 5 Column 11 1 b = Columns 1 through 10 0 1 1 1 0 0 1 0 0 0 Column 11 0 s = 1110010000 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 12 1 3 counter = 13 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 g = 6 notg = 1 2 3 4 5 7 8 9 10 11 b = Columns 1 through 10 1 2 2 2 1 1 2 1 4 5 Column 11 1 b = Columns 1 through 10 0 0 0 0 0 1 0 0 0 0 Column 11 0 s = 100000 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 13 1 3 1 counter = 14 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 g = 9 notg = 1 2 3 4 5 6 7 8 10 11 b = Columns 1 through 10 1 2 2 2 1 3 2 1 1 5 Column 11 1 b = Columns 1 through 10 0 0 0 0 0 0 0 0 1 0 Column 11 0 s = 100 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 14 1 3 1 1 counter = 15 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 g = 10 notg = 1 2 3 4 5 6 7 8 9 11 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 1 Column 11 1 b = Columns 1 through 10 0 0 0 0 0 0 0 0 0 1 Column 11 0 s = 10 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 15 1 3 1 1 1 counter = 16 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 16 1 3 1 1 1 0 counter = 17 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 17 1 3 1 1 1 0 0 counter = 18 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 18 1 3 1 1 1 0 0 0 counter = 19 b = Columns 1 through 10 1 2 2 2 1 3 2 1 4 5 Column 11 1 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 19 1 3 1 1 1 0 0 0 0 longest_sequence = 3 pouriiegale = 12 autotal = 12 infact = 2 sol = 2

2   Pass
%% a = [1 1 1 2 2 2 3 3 3]; y_correct = [1 2 3]; assert(isequal(longrun(a),y_correct))

counter = 0 counter = 1 b = 1 1 1 2 2 2 3 3 3 C = 0 counter = 2 b = 1 1 1 2 2 2 3 3 3 C = 0 0 counter = 3 b = 1 1 1 2 2 2 3 3 3 C = 0 0 0 counter = 4 b = 1 1 1 2 2 2 3 3 3 C = 0 0 0 0 counter = 5 b = 1 1 1 2 2 2 3 3 3 C = 0 0 0 0 0 counter = 6 b = 1 1 1 2 2 2 3 3 3 C = 0 0 0 0 0 0 counter = 7 b = 1 1 1 2 2 2 3 3 3 C = 0 0 0 0 0 0 0 counter = 8 b = 1 1 1 2 2 2 3 3 3 C = 0 0 0 0 0 0 0 0 counter = 9 b = 1 1 1 2 2 2 3 3 3 C = 0 0 0 0 0 0 0 0 0 counter = 10 b = 1 1 1 2 2 2 3 3 3 C = 0 0 0 0 0 0 0 0 0 0 counter = 11 b = 1 1 1 2 2 2 3 3 3 g = 1 2 3 notg = 4 5 6 7 8 9 b = 1 1 1 2 2 2 3 3 3 b = 1 1 1 0 0 0 0 0 0 s = 111000000 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Column 11 3 counter = 12 b = 1 1 1 2 2 2 3 3 3 g = 4 5 6 notg = 1 2 3 7 8 9 b = 1 1 1 1 1 1 3 3 3 b = 0 0 0 1 1 1 0 0 0 s = 111000 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 12 3 3 counter = 13 b = 1 1 1 2 2 2 3 3 3 g = 7 8 9 notg = 1 2 3 4 5 6 b = 1 1 1 2 2 2 1 1 1 b = 0 0 0 0 0 0 1 1 1 s = 111 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 13 3 3 3 counter = 14 b = 1 1 1 2 2 2 3 3 3 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 14 3 3 3 0 counter = 15 b = 1 1 1 2 2 2 3 3 3 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 15 3 3 3 0 0 counter = 16 b = 1 1 1 2 2 2 3 3 3 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 16 3 3 3 0 0 0 counter = 17 b = 1 1 1 2 2 2 3 3 3 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 17 3 3 3 0 0 0 0 counter = 18 b = 1 1 1 2 2 2 3 3 3 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 18 3 3 3 0 0 0 0 0 counter = 19 b = 1 1 1 2 2 2 3 3 3 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 19 3 3 3 0 0 0 0 0 0 longest_sequence = 3 pouriiegale = 11 autotal = 11 12 13 infact = 1 infact = 1 2 infact = 1 2 3 sol = 1 2 3

3   Pass
%% a = [-2 -2 -2 -2 -1 0 3]; y_correct = -2; assert(isequal(longrun(a),y_correct))

counter = 0 counter = 1 b = -2 -2 -2 -2 -1 0 3 C = 0 counter = 2 b = -2 -2 -2 -2 -1 0 3 C = 0 0 counter = 3 b = -2 -2 -2 -2 -1 0 3 C = 0 0 0 counter = 4 b = -2 -2 -2 -2 -1 0 3 C = 0 0 0 0 counter = 5 b = -2 -2 -2 -2 -1 0 3 C = 0 0 0 0 0 counter = 6 b = -2 -2 -2 -2 -1 0 3 C = 0 0 0 0 0 0 counter = 7 b = -2 -2 -2 -2 -1 0 3 C = 0 0 0 0 0 0 0 counter = 8 b = -2 -2 -2 -2 -1 0 3 g = 1 2 3 4 notg = 5 6 7 b = 1 1 1 1 -1 0 3 b = 1 1 1 1 0 0 0 s = 1111000 C = 0 0 0 0 0 0 0 4 counter = 9 b = -2 -2 -2 -2 -1 0 3 g = 5 notg = 1 2 3 4 6 7 b = -2 -2 -2 -2 1 0 3 b = 0 0 0 0 1 0 0 s = 100 C = 0 0 0 0 0 0 0 4 1 counter = 10 b = -2 -2 -2 -2 -1 0 3 g = 6 notg = 1 2 3 4 5 7 b = -2 -2 -2 -2 -1 1 3 b = 0 0 0 0 0 1 0 s = 10 C = 0 0 0 0 0 0 0 4 1 1 counter = 11 b = -2 -2 -2 -2 -1 0 3 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Column 11 0 counter = 12 b = -2 -2 -2 -2 -1 0 3 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Columns 11 through 12 0 0 counter = 13 b = -2 -2 -2 -2 -1 0 3 g = 7 notg = 1 2 3 4 5 6 b = -2 -2 -2 -2 -1 0 1 b = 0 0 0 0 0 0 1 s = 1 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Columns 11 through 13 0 0 1 counter = 14 b = -2 -2 -2 -2 -1 0 3 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Columns 11 through 14 0 0 1 0 counter = 15 b = -2 -2 -2 -2 -1 0 3 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Columns 11 through 15 0 0 1 0 0 counter = 16 b = -2 -2 -2 -2 -1 0 3 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Columns 11 through 16 0 0 1 0 0 0 counter = 17 b = -2 -2 -2 -2 -1 0 3 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Columns 11 through 17 0 0 1 0 0 0 0 counter = 18 b = -2 -2 -2 -2 -1 0 3 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Columns 11 through 18 0 0 1 0 0 0 0 0 counter = 19 b = -2 -2 -2 -2 -1 0 3 C = Columns 1 through 10 0 0 0 0 0 0 0 4 1 1 Columns 11 through 19 0 0 1 0 0 0 0 0 0 longest_sequence = 4 pouriiegale = 8 autotal = 8 infact = -2 sol = -2

4   Fail
%% a=[0 1 1 1 0 2 2 0 1 1 1 0]; y_correct = [1 1]; assert(isequal(longrun(a),y_correct))

Error: Assertion failed.

5   Pass
%% a=[3 3 3 2 2 1 6]'; y_correct=3; assert(isequal(longrun(a),y_correct))

counter = 0 counter = 1 b = 3 3 3 2 2 1 6 C = 0 counter = 2 b = 3 3 3 2 2 1 6 C = 0 0 counter = 3 b = 3 3 3 2 2 1 6 C = 0 0 0 counter = 4 b = 3 3 3 2 2 1 6 C = 0 0 0 0 counter = 5 b = 3 3 3 2 2 1 6 C = 0 0 0 0 0 counter = 6 b = 3 3 3 2 2 1 6 C = 0 0 0 0 0 0 counter = 7 b = 3 3 3 2 2 1 6 C = 0 0 0 0 0 0 0 counter = 8 b = 3 3 3 2 2 1 6 C = 0 0 0 0 0 0 0 0 counter = 9 b = 3 3 3 2 2 1 6 C = 0 0 0 0 0 0 0 0 0 counter = 10 b = 3 3 3 2 2 1 6 C = 0 0 0 0 0 0 0 0 0 0 counter = 11 b = 3 3 3 2 2 1 6 g = 6 notg = 1 2 3 4 5 7 b = 3 3 3 2 2 1 6 b = 0 0 0 0 0 1 0 s = 10 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Column 11 1 counter = 12 b = 3 3 3 2 2 1 6 g = 4 5 notg = 1 2 3 6 7 b = 3 3 3 1 1 1 6 b = 0 0 0 1 1 0 0 s = 1100 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 12 1 2 counter = 13 b = 3 3 3 2 2 1 6 g = 1 2 3 notg = 4 5 6 7 b = 1 1 1 2 2 1 6 b = 1 1 1 0 0 0 0 s = 1110000 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 13 1 2 3 counter = 14 b = 3 3 3 2 2 1 6 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 14 1 2 3 0 counter = 15 b = 3 3 3 2 2 1 6 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 15 1 2 3 0 0 counter = 16 b = 3 3 3 2 2 1 6 g = 7 notg = 1 2 3 4 5 6 b = 3 3 3 2 2 1 1 b = 0 0 0 0 0 0 1 s = 1 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 16 1 2 3 0 0 1 counter = 17 b = 3 3 3 2 2 1 6 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 17 1 2 3 0 0 1 0 counter = 18 b = 3 3 3 2 2 1 6 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 18 1 2 3 0 0 1 0 0 counter = 19 b = 3 3 3 2 2 1 6 C = Columns 1 through 10 0 0 0 0 0 0 0 0 0 0 Columns 11 through 19 1 2 3 0 0 1 0 0 0 longest_sequence = 3 pouriiegale = 13 autotal = 13 infact = 3 sol = 3

6   Fail
%% a=[3 3 3 2 2 2 1 6]'; y_correct=[3 2]'; assert(isequal(longrun(a),y_correct))

Error: Assertion failed.

7   Fail
%% a=[1 2 3 4 5]'; y_correct=a; assert(isequal(longrun(a),y_correct))

Error: Assertion failed.