Cody

# Problem 29. Nearest Numbers

Solution 1908470

Submitted on 22 Aug 2019
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
A = [30 46 16 -46 35 44 18 26 25 -10]; correct = [8 9]; [i1 i2] = nearestNumbers(A); assert(isequal([i1 i2],correct))

index1 = 2 index2 = 1

Assertion failed.

2   Fail
A = [1555 -3288 2061 -4681 -2230 -4538 -4028 3235 1949 -1829]; correct = [3 9]; [i1 i2] = nearestNumbers(A); assert(isequal([i1 i2],correct))

index1 = 2 3 4 5 6 7 8 9 10 1 3 4 5 6 7 8 9 10 1 2 4 5 6 7 8 9 10 1 2 3 5 6 7 8 9 10 1 2 3 4 6 7 8 9 10 1 2 3 4 5 7 8 9 10 1 2 3 4 5 6 8 9 10 1 2 3 4 5 6 7 9 10 1 2 3 4 5 6 7 8 10 1 2 3 4 5 6 7 8 9 index2 = 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10

Assertion failed.

3   Fail
A = [-1 1 10 -10]; correct = [1 2]; [i1 i2] = nearestNumbers(A); assert(isequal([i1 i2],correct))

Matrix dimensions must agree. Error in nearestNumbers (line 2) matrix = abs(repmat(A, [10, 1]) - repmat(A.', [1, 10])); Error in Test3 (line 3) [i1 i2] = nearestNumbers(A);

4   Fail
A = [0 1000 -2000 1001 0]; correct = [1 5]; [i1 i2] = nearestNumbers(A); assert(isequal([i1 i2],correct))

Matrix dimensions must agree. Error in nearestNumbers (line 2) matrix = abs(repmat(A, [10, 1]) - repmat(A.', [1, 10])); Error in Test4 (line 3) [i1 i2] = nearestNumbers(A);

5   Fail
A = [1:1000 0.5]; correct = [1 1001]; [i1 i2] = nearestNumbers(A); assert(isequal([i1 i2],correct))

Matrix dimensions must agree. Error in nearestNumbers (line 2) matrix = abs(repmat(A, [10, 1]) - repmat(A.', [1, 10])); Error in Test5 (line 3) [i1 i2] = nearestNumbers(A);

6   Fail
% Area codes A = [847 217 508 312 212]; correct = [2 5]; [i1 i2] = nearestNumbers(A); assert(isequal([i1 i2],correct))

Matrix dimensions must agree. Error in nearestNumbers (line 2) matrix = abs(repmat(A, [10, 1]) - repmat(A.', [1, 10])); Error in Test6 (line 4) [i1 i2] = nearestNumbers(A);

7   Fail
% Zip codes A = [60048 61802 01702 60601 10001]; correct = [1 4]; [i1 i2] = nearestNumbers(A); assert(isequal([i1 i2],correct))

Matrix dimensions must agree. Error in nearestNumbers (line 2) matrix = abs(repmat(A, [10, 1]) - repmat(A.', [1, 10])); Error in Test7 (line 4) [i1 i2] = nearestNumbers(A);