Cody

# Problem 15. Find the longest sequence of 1's in a binary sequence.

Solution 1995670

Submitted on 29 Oct 2019 by William Katzianer
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 = '0'; y_correct = 0; assert(isequal(lengthOnes(x),y_correct))

s = 0 s(1): 0 n: 0 y = 0

2   Pass
x = '1'; y_correct = 1; assert(isequal(lengthOnes(x),y_correct))

s = 1 s(1): 1 n: 1 y = 1

3   Pass
x = '01'; y_correct = 1; assert(isequal(lengthOnes(x),y_correct))

s = 0 1 s(1): 0 n: 0 s(2): 1 n: 1 y = 1

4   Pass
x = '10'; y_correct = 1; assert(isequal(lengthOnes(x),y_correct))

s = 1 0 s(1): 1 n: 1 s(2): 0 n: 0 y = 1

5   Pass
x = '00'; y_correct = 0; assert(isequal(lengthOnes(x),y_correct))

s = 0 0 s(1): 0 n: 0 s(2): 0 n: 0 y = 0

6   Pass
x = '11'; y_correct = 2; assert(isequal(lengthOnes(x),y_correct))

s = 1 1 s(1): 1 n: 1 s(2): 1 n: 2 y = 2

7   Pass
x = '1111111111'; y_correct = 10; assert(isequal(lengthOnes(x),y_correct))

s = 1 1 1 1 1 1 1 1 1 1 s(1): 1 n: 1 s(2): 1 n: 2 s(3): 1 n: 3 s(4): 1 n: 4 s(5): 1 n: 5 s(6): 1 n: 6 s(7): 1 n: 7 s(8): 1 n: 8 s(9): 1 n: 9 s(10): 1 n: 10 y = 10

8   Pass
x = '100101011111010011111'; y_correct = 5; assert(isequal(lengthOnes(x),y_correct))

s = 1 0 0 1 0 1 0 1 1 1 1 1 0 1 0 0 1 1 1 1 1 s(1): 1 n: 1 s(2): 0 n: 0 s(3): 0 n: 0 s(4): 1 n: 1 s(5): 0 n: 0 s(6): 1 n: 1 s(7): 0 n: 0 s(8): 1 n: 1 s(9): 1 n: 2 s(10): 1 n: 3 s(11): 1 n: 4 s(12): 1 n: 5 s(13): 0 n: 0 s(14): 1 n: 1 s(15): 0 n: 0 s(16): 0 n: 0 s(17): 1 n: 1 s(18): 1 n: 2 s(19): 1 n: 3 s(20): 1 n: 4 s(21): 1 n: 5 y = 5

9   Pass
x = '01010101010101010101010101'; y_correct = 1; assert(isequal(lengthOnes(x),y_correct))

s = 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 s(1): 0 n: 0 s(2): 1 n: 1 s(3): 0 n: 0 s(4): 1 n: 1 s(5): 0 n: 0 s(6): 1 n: 1 s(7): 0 n: 0 s(8): 1 n: 1 s(9): 0 n: 0 s(10): 1 n: 1 s(11): 0 n: 0 s(12): 1 n: 1 s(13): 0 n: 0 s(14): 1 n: 1 s(15): 0 n: 0 s(16): 1 n: 1 s(17): 0 n: 0 s(18): 1 n: 1 s(19): 0 n: 0 s(20): 1 n: 1 s(21): 0 n: 0 s(22): 1 n: 1 s(23): 0 n: 0 s(24): 1 n: 1 s(25): 0 n: 0 s(26): 1 n: 1 y = 1

10   Pass
x = '0101010111000101110001011100010100001110110100000000110001001000001110001000111010101001101100001111'; y_correct = 4; assert(isequal(lengthOnes(x),y_correct))

s = Columns 1 through 30 0 1 0 1 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 1 0 0 0 1 Columns 31 through 60 0 1 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 Columns 61 through 90 1 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 1 0 1 0 0 1 1 0 Columns 91 through 100 1 1 0 0 0 0 1 1 1 1 s(1): 0 n: 0 s(2): 1 n: 1 s(3): 0 n: 0 s(4): 1 n: 1 s(5): 0 n: 0 s(6): 1 n: 1 s(7): 0 n: 0 s(8): 1 n: 1 s(9): 1 n: 2 s(10): 1 n: 3 s(11): 0 n: 0 s(12): 0 n: 0 s(13): 0 n: 0 s(14): 1 n: 1 s(15): 0 n: 0 s(16): 1 n: 1 s(17): 1 n: 2 s(18): 1 n: 3 s(19): 0 n: 0 s(20): 0 n: 0 s(21): 0 n: 0 s(22): 1 n: 1 s(23): 0 n: 0 s(24): 1 n: 1 s(25): 1 n: 2 s(26): 1 n: 3 s(27): 0 n: 0 s(28): 0 n: 0 s(29): 0 n: 0 s(30): 1 n: 1 s(31): 0 n: 0 s(32): 1 n: 1 s(33): 0 n: 0 s(34): 0 n: 0 s(35): 0 n: 0 s(36): 0 n: 0 s(37): 1 n: 1 s(38): 1 n: 2 s(39): 1 n: 3 s(40): 0 n: 0 s(41): 1 n: 1 s(42): 1 n: 2 s(43): 0 n: 0 s(44): 1 n: 1 s(45): 0 n: 0 s(46): 0 n: 0 s(47): 0 n: 0 s(48): 0 n: 0 s(49): 0 n: 0 s(50): 0 n: 0 s(51): 0 n: 0 s(52): 0 n: 0 s(53): 1 n: 1 s(54): 1 n: 2 s(55): 0 n: 0 s(56): 0 n: 0 s(57): 0 n: 0 s(58): 1 n: 1 s(59): 0 n: 0 s(60): 0 n: 0 s(61): 1 n: 1 s(62): 0 n: 0 s(63): 0 n: 0 s(64): 0 n: 0 s(65): 0 n: 0 s(66): 0 n: 0 s(67): 1 n: 1 s(68): 1 n: 2 s(69): 1 n: 3 s(70): 0 n: 0 s(71): 0 n: 0 s(72): 0 n: 0 s(73): 1 n: 1 s(74): 0 n: 0 s(75): 0 n: 0 s(76): 0 n: 0 s(77): 1 n: 1 s(78): 1 n: 2 s(79): 1 n: 3 s(80): 0 n: 0 s(81): 1 n: 1 s(82): 0 n: 0 s(83): 1 n: 1 s(84): 0 n: 0 s(85): 1 n: 1 s(86): 0 n: 0 s(87): 0 n: 0 s(88): 1 n: 1 s(89): 1 n: 2 s(90): 0 n: 0 s(91): 1 n: 1 s(92): 1 n: 2 s(93): 0 n: 0 s(94): 0 n: 0 s(95): 0 n: 0 s(96): 0 n: 0 s(97): 1 n: 1 s(98): 1 n: 2 s(99): 1 n: 3 s(100): 1 n: 4 y = 4