Cody

Problem 795. Joining Ranges

Solution 2776003

Submitted on 4 Aug 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
x = [0 5; 10 3; 20 15; 16 19; 25 25]; y_correct = [0 10;15 20;25 25]; assert(isequal(joinRanges(x),y_correct))

A = 0 3 15 16 25 5 10 19 20 25 A = 0 5 3 10 15 19 16 20 25 25 B = 0 5 3 10 15 19 16 20 25 25 ans = 2 4 6 8 B = 0 NaN NaN 10 15 19 16 20 25 25 B = 0 NaN NaN 10 15 NaN NaN 20 25 25 y = 0 20 10 25 15 25

Assertion failed.

2   Pass
x = [-10 -5; 0 -8; -1 5]; y_correct = [-10 5]; assert(isequal(joinRanges(x),y_correct))

A = -10 -8 -1 -5 0 5 A = -10 -5 -8 0 -1 5 B = -10 -5 -8 0 -1 5 ans = 2 4 B = -10 NaN NaN 0 -1 5 B = -10 NaN NaN NaN NaN 5 y = -10 5

3   Pass
x = [-50 0; 0 50; 100 50; -50 -100]; y_correct = [-100 100]; assert(isequal(joinRanges(x),y_correct))

A = -100 -50 0 50 -50 0 50 100 A = -100 -50 -50 0 0 50 50 100 B = -100 -50 -50 0 0 50 50 100 ans = 2 4 6 B = -100 NaN NaN 0 0 50 50 100 B = -100 NaN NaN NaN NaN 50 50 100 B = -100 NaN NaN NaN NaN NaN NaN 100 y = -100 100

4   Fail
x = [99 51; -49 -1; -51 -99; 1 49]; y_correct = [-99 -51;-49 -1;1 49;51 99]; assert(isequal(joinRanges(x),y_correct))

A = -99 -49 1 51 -51 -1 49 99 A = -99 -51 -49 -1 1 49 51 99 B = -99 -51 -49 -1 1 49 51 99 ans = 2 4 6 y = -99 1 -51 49 -49 51 -1 99

Assertion failed.

5   Pass
x = [-inf inf]; y_correct = x; assert(isequal(joinRanges(x),y_correct))

A = -Inf Inf A = -Inf Inf B = -Inf Inf ans = 1×0 empty double row vector y = -Inf Inf

6   Fail
x = [0 -42; -inf -10; inf 42]; y_correct = [-Inf 0;42 Inf]; assert(isequal(joinRanges(x),y_correct))

A = -Inf -42 42 -10 0 Inf A = -Inf -10 -42 0 42 Inf B = -Inf -10 -42 0 42 Inf ans = 2 4 B = -Inf NaN NaN 0 42 Inf y = -Inf 42 0 Inf

Assertion failed.

7   Fail
x = [36.154 63.178; 12.007 -5.156; -0.519 17.651]; y_correct = [-5.156 17.651;36.154 63.178]; assert(isequal(joinRanges(x),y_correct))

A = -5.1560 -0.5190 36.1540 12.0070 17.6510 63.1780 A = -5.1560 12.0070 -0.5190 17.6510 36.1540 63.1780 B = -5.1560 12.0070 -0.5190 17.6510 36.1540 63.1780 ans = 2 4 B = -5.1560 NaN NaN 17.6510 36.1540 63.1780 y = -5.1560 36.1540 17.6510 63.1780

Assertion failed.

8   Pass
assert(isempty(strfind(evalc('type joinRanges'), 'regexp')));