Cody

# Problem 2545. compress sequence into intervals

Solution 2233879

Submitted on 25 Apr 2020
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   Fail
sequence = [1 2 3 4 5 7 8 9 24 25 26 27 28 29 30 31 32]; bounds = [1 5 7 9 24 32]; assert(isequal(CompressSequence(sequence), bounds))

t = 5 8 ans = 1 5 ans = 1 5 7 9 ans = 1 5 7 9 7 32

Assertion failed.

2   Fail
sequence = [100:200 300:400]; bounds = [100 200 300 400]; assert(isequal(CompressSequence(sequence), bounds))

t = 101 ans = 100 200 ans = 100 200 400

Assertion failed.

3   Fail
sequence = -10:10; bounds = [-10 10]; assert(isequal(CompressSequence(sequence), bounds))

t = 1×0 empty double row vector ans = -10 -9

Assertion failed.

4   Fail
sequence = [9 11]; bounds = [9 9 11 11]; assert(isequal(CompressSequence(sequence), bounds))

t = 1 ans = 9 9 ans = 9 9 11

Assertion failed.

5   Fail
sequence = 1:2:99; temp = [1:2:99; 1:2:99]; bounds = temp(:)'; assert(isequal(CompressSequence(sequence), bounds))

t = Columns 1 through 30 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 30 Columns 31 through 49 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 ans = 1 1 ans = 1 1 3 3 ans = 1 1 3 3 5 5 ans = 1 1 3 3 5 5 7 7 ans = 1 1 3 3 5 5 7 7 9 9 ans = 1 1 3 3 5 5 7 7 9 9 11 11 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 ans = 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 32 31 31 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 34 31 31 33 33 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 36 31 31 33 33 35 35 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 38 31 31 33 33 35 35 37 37 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 40 31 31 33 33 35 35 37 37 39 39 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 42 31 31 33 33 35 35 37 37 39 39 41 41 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 44 31 31 33 33 35 35 37 37 39 39 41 41 43 43 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 46 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 48 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 50 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 52 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 54 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 56 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 58 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 60 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 60 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 Columns 61 through 62 61 61 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 60 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 Columns 61 through 64 61 61 63 63 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 60 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 Columns 61 through 66 61 61 63 63 65 65 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 60 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 Columns 61 through 68 61 61 63 63 65 65 67 67 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 60 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 Columns 61 through 70 61 61 63 63 65 65 67 67 69 69 ans = Columns 1 through 30 1 1 3 3 5 5 7 7 9 9 11 11 13 13 15 15 17 17 19 19 21 21 23 23 25 25 27 27 29 29 Columns 31 through 60 31 31 33 33 35 35 37 37 39 39 41 41 43 43 45 45 47 47 49 49 51 51 53 53 55 55 57 57 59 59 Columns 61 through 72 61 61 63 63 65 65 67 67 69 69 71 71 ans = Columns 1 through 30 1 1 3 3 5 ...

Assertion failed.

### Community Treasure Hunt

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

Start Hunting!