Cody

# Problem 29. Nearest Numbers

Solution 1919081

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

m = Inf 16 14 76 5 14 12 4 5 40 Inf Inf 30 92 11 2 28 20 21 56 Inf Inf Inf 62 19 28 2 10 9 26 Inf Inf Inf Inf 81 90 64 72 71 36 Inf Inf Inf Inf Inf 9 17 9 10 45 Inf Inf Inf Inf Inf Inf 26 18 19 54 Inf Inf Inf Inf Inf Inf Inf 8 7 28 Inf Inf Inf Inf Inf Inf Inf Inf 1 36 Inf Inf Inf Inf Inf Inf Inf Inf Inf 35 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf v = Inf 16 14 62 5 2 2 4 1 26 index1 = 1 1 1 3 1 2 3 1 8 3 v = 1 index2 = 9 index1 = 8

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

m = Inf 4843 506 6236 3785 6093 5583 1680 394 3384 Inf Inf 5349 1393 1058 1250 740 6523 5237 1459 Inf Inf Inf 6742 4291 6599 6089 1174 112 3890 Inf Inf Inf Inf 2451 143 653 7916 6630 2852 Inf Inf Inf Inf Inf 2308 1798 5465 4179 401 Inf Inf Inf Inf Inf Inf 510 7773 6487 2709 Inf Inf Inf Inf Inf Inf Inf 7263 5977 2199 Inf Inf Inf Inf Inf Inf Inf Inf 1286 5064 Inf Inf Inf Inf Inf Inf Inf Inf Inf 3778 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf v = Inf 4843 506 1393 1058 143 510 1174 112 401 index1 = 1 1 1 2 2 4 6 3 3 5 v = 112 index2 = 9 index1 = 3

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

m = Inf 2 11 9 Inf Inf 9 11 Inf Inf Inf 20 Inf Inf Inf Inf v = Inf 2 9 9 index1 = 1 1 2 1 v = 2 index2 = 2 index1 = 1

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

m = Inf 1000 2000 1001 0 Inf Inf 3000 1 1000 Inf Inf Inf 3001 2000 Inf Inf Inf Inf 1001 Inf Inf Inf Inf Inf v = Inf 1000 2000 1 0 index1 = 1 1 1 2 1 v = 0 index2 = 5 index1 = 1

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

m = Columns 1 through 18 Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 17.0000 Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 5.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 4.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 3.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 2.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf 1.0000 Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf Inf ...

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

m = Inf 630 339 535 635 Inf Inf 291 95 5 Inf Inf Inf 196 296 Inf Inf Inf Inf 100 Inf Inf Inf Inf Inf v = Inf 630 291 95 5 index1 = 1 1 2 2 2 v = 5 index2 = 5 index1 = 2

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

m = Inf 1754 58346 553 50047 Inf Inf 60100 1201 51801 Inf Inf Inf 58899 8299 Inf Inf Inf Inf 50600 Inf Inf Inf Inf Inf v = Inf 1754 58346 553 8299 index1 = 1 1 1 1 3 v = 553 index2 = 4 index1 = 1