Cody

# Problem 29. Nearest Numbers

Solution 2095843

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

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

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 = 1 index2 = 2 index1 = 1 index2 = 3 index1 = 1 index2 = 4 index1 = 1 index2 = 5 index1 = 1 index2 = 6 index1 = 1 index2 = 7 index1 = 1 index2 = 8 index1 = 1 index2 = 9 index1 = 1 index2 = 10 index1 = 2 index2 = 3 index1 = 2 index2 = 4 index1 = 2 index2 = 5 index1 = 2 index2 = 6 index1 = 2 index2 = 7 index1 = 2 index2 = 8 index1 = 2 index2 = 9 index1 = 2 index2 = 10 index1 = 3 index2 = 4 index1 = 3 index2 = 5 index1 = 3 index2 = 6 index1 = 3 index2 = 7 index1 = 3 index2 = 8 index1 = 3 index2 = 9 index1 = 3 index2 = 10 index1 = 4 index2 = 5 index1 = 4 index2 = 6 index1 = 4 index2 = 7 index1 = 4 index2 = 8 index1 = 4 index2 = 9 index1 = 4 index2 = 10 index1 = 5 index2 = 6 index1 = 5 index2 = 7 index1 = 5 index2 = 8 index1 = 5 index2 = 9 index1 = 5 index2 = 10 index1 = 6 index2 = 7 index1 = 6 index2 = 8 index1 = 6 index2 = 9 index1 = 6 index2 = 10 index1 = 7 index2 = 8 index1 = 7 index2 = 9 index1 = 7 index2 = 10 index1 = 8 index2 = 9 index1 = 8 index2 = 10 index1 = 9 index2 = 10

Assertion failed.

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

index1 = 1 index2 = 2 index1 = 1 index2 = 3 index1 = 1 index2 = 4 index1 = 2 index2 = 3 index1 = 2 index2 = 4 index1 = 3 index2 = 4

Assertion failed.

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

index1 = 1 index2 = 2 index1 = 1 index2 = 3 index1 = 1 index2 = 4 index1 = 1 index2 = 5 index1 = 2 index2 = 3 index1 = 2 index2 = 4 index1 = 2 index2 = 5 index1 = 3 index2 = 4 index1 = 3 index2 = 5 index1 = 4 index2 = 5

Assertion failed.

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

index1 = 1 index2 = 2 index1 = 1 index2 = 3 index1 = 1 index2 = 4 index1 = 1 index2 = 5 index1 = 1 index2 = 6 index1 = 1 index2 = 7 index1 = 1 index2 = 8 index1 = 1 index2 = 9 index1 = 1 index2 = 10 index1 = 1 index2 = 11 index1 = 1 index2 = 12 index1 = 1 index2 = 13 index1 = 1 index2 = 14 index1 = 1 index2 = 15 index1 = 1 index2 = 16 index1 = 1 index2 = 17 index1 = 1 index2 = 18 index1 = 1 index2 = 19 index1 = 1 index2 = 20 index1 = 1 index2 = 21 index1 = 1 index2 = 22 index1 = 1 index2 = 23 index1 = 1 index2 = 24 index1 = 1 index2 = 25 index1 = 1 index2 = 26 index1 = 1 index2 = 27 index1 = 1 index2 = 28 index1 = 1 index2 = 29 index1 = 1 index2 = 30 index1 = 1 index2 = 31 index1 = 1 index2 = 32 index1 = 1 index2 = 33 index1 = 1 index2 = 34 index1 = 1 index2 = 35 index1 = 1 index2 = 36 index1 = 1 index2 = 37 index1 = 1 index2 = 38 index1 = 1 index2 = 39 index1 = 1 index2 = 40 index1 = 1 index2 = 41 index1 = 1 index2 = 42 index1 = 1 index2 = 43 index1 = 1 index2 = 44 index1 = 1 index2 = 45 index1 = 1 index2 = 46 index1 = 1 index2 = 47 index1 = 1 index2 = 48 index1 = 1 index2 = 49 index1 = 1 index2 = 50 index1 = 1 index2 = 51 index1 = 1 index2 = 52 index1 = 1 index2 = 53 index1 = 1 index2 = 54 index1 = 1 index2 = 55 index1 = 1 index2 = 56 index1 = 1 index2 = 57 index1 = 1 index2 = 58 index1 = 1 index2 = 59 index1 = 1 index2 = 60 index1 = 1 index2 = 61 index1 = 1 index2 = 62 index1 = 1 index2 = 63 index1 = 1 index2 = 64 index1 = 1 index2 = 65 index1 = 1 index2 = 66 index1 = 1 index2 = 67 index1 = 1 index2 = 68 index1 = 1 index2 = 69 index1 = 1 index2 = 70 index1 = 1 index2 = 71 index1 = 1 index2 = 72 index1 = 1 index2 = 73 index1 = 1 index2 = 74 index1 = 1 index2 = 75 index1 = 1 index2 = 76 index1 = 1 index2 = 77 index1 = 1 index2 = 78 index1 = 1 index2 = 79 index1 = 1 index2 = 80 index1 = 1 index2 = 81 index1 = 1 index2 = 82 index1 = 1 index2 = 83 index1 = 1 index2 = 84 index1 = 1 index2 = 85 index1 = 1 index2 = 86 index1 = 1 index2 = 87 index1 = 1 index2 = 88 index1 = 1 index2 = 89 index1 = 1 index2 = 90 index1 = 1 index2 = 91 index1 = 1 index2 = 92 index1 = 1 index2 = 93 index1 = 1 index2 = 94 index1 = 1 index2 = 95 index1 = 1 index2 = 96 index1 = 1 index2 = 97 index1 = 1 index2 = 98 index1 = 1 index2 = 99 index1 = 1 index2 = 100 index1 = 1 index2 = 101 index1 = 1 index2 = 102 index1 = 1 index2 = 103 index1 = 1 index2 = 104 index1 = 1 index2 = 105 index1 = 1 index2 = 106 index1 = 1 index2 = 107 index1 = 1 index2 = 108 index1 = 1 index2 = 109 index1 = 1 index2 = 110 index1 = 1 index2 = 111 index1 = 1 index2 = 112 index1 = 1 index2 = 113 index1 = 1 index2 = 114 index1 = 1 index2 = 115 index1 = 1 index2 = 116 index1 = 1 index2 = 117 index1 = 1 index2 = 118 index1 = 1 index2 = 119 index1 = 1 index2 = 120 index1 = 1 index2 = 121 index1 = 1 index2 = 122 index1 = 1 index2 = 123 index1 = 1 index2 = 124 index1 = 1 index2 = 125 index1 = 1 index2 = 126 index1 = 1 index2 = 127 index1 = 1 index2 = 128 index1 = 1 index2 = 129 index1 = 1 index2 = 130 index1 = 1 index2 = 131 index1 = 1 index2 = 132 index1 = 1 index2 = 133 index1 = 1 index2 = 134 index1 = 1 index2 = 135 index1 = 1 index2 = 136 index1 = 1 index2 = 137 index1 = 1 index2 = 138 index1 = 1 index2 = 139 index1 = 1 index2 = 140 index1 = 1 index2 = 141 index1 = 1 index2 = 142 index1 = 1 index2 = 143 index1 = 1 index2 = 144 index1 = 1 index2 = 145 index1 = 1 index2 = 146 index1 = 1 index2 = 147 index1 = 1 index2 = 148 index1 = 1 index2 = 149 index1 = 1 index2 = 150 index1 = 1 index2 = 151 index1 = 1 index2 = 152 index1 = 1 index2 = 153 index1 = 1 index2 = 154 index1 = 1 index2 = 155 index1 = 1 index2 = 156 index1 = 1 index2 = 157 index1 = 1 index2 = 158 index1 = 1 index2 = 159 index1 = 1 index2 = 160 index1 = 1 index2 = 161 index1 = 1 index2 = 162 index1 = 1 index2 = 163 index1 = 1 index2 = 164 index1 = 1 index2 = 165 index1 = 1 index2 = 166 index1 = 1 index2 = 167 index1 = 1 index2 = 168 index1 = 1 index2 = 169 index1 = 1 index2 = 170 index1 = 1 index2 = 171 index1 = 1 index2 = 172 index1 = 1 index2 = 173 index1 = 1 index2 = 174 index1 = 1 index2 = 175 index1 = 1 index2 = 176 index1 = 1 index2 = 177 index1 = 1 index2 = 178 index1 = 1 index2 = 179 index1 = 1 index2 = 180 index1 = 1 index2 = 181 index1 = 1 index2 = 182 index1 = 1 index2 = 183 index1 = 1 index2 = 184 index1 = 1 index2 = 185 index1 = 1 index2 = 186 index1 = 1 index2 = 187 index1 = 1 index2 = 188 index1 = 1 index2 = 189 index1 = 1 index2 = 190 index1 = 1 index2 = 191 index1 = 1 index2 = 192 index1 = 1 index2 = 193 index1 = 1 index2 = 194 index1 = 1 index2 = 195 index1 = 1 index2 = 196 index1 = 1 index2 = 197 index1 = 1 index2 = 198 index1 = 1 index2 = 199 index1 = 1 index2 = 200 index1 = 1 index2 = 201 index1 = 1 index2 = 202 index1 = 1 index2 = 203 index1 = 1 index2 = 204 index1 = 1 index2 = 205 index1 = 1 index2 = 206 index1 = 1 index2 = 207 index1 = 1 index2 = 208 index1 = 1 index2 = 209 index1 = 1 index2 = 210 index1 = 1 index2 = 211 index1 = 1 index2 = 212 index1 = 1 index2 = 213 index1 = 1 index2 = 214 index1 = 1 index2 = 215 index1 = 1 index2 = 216 index1 = 1 index2 = 217 index1 = 1 index2 = 218 index1 = 1 index2 = 219 index1 = 1 index2 = 220 index1 = 1 index2 = 221 index1 = 1 index2 = 222 index1 = 1 index2 = 223 index1 = 1 index2 = 224 index1 = 1 index2 = 225 index1 = 1 index2 = 226 index1 = 1 index2 = 227 index1 = 1 index2 = 228 index1 = 1 index2 = 229 index1 = 1 index2 = 230 index1 = 1 index2 = 231 index1 = 1 index2 = 232 index1 = 1 index2 = 233 index1 = 1 index2 = 234 index1 = 1 index2 = 235 index1 = 1 index2 = 236 index1 = 1 index2 = 237 index1 = 1 index2 = 238 index1 = 1 index2 = 239 index1 = 1 index2 = 240 index1 = 1 index2 = 241 index1 = 1 index2 = 242 index1 = 1 index2 = 243 index1 = 1 index2 = 244 index1 = 1 index2 = 245 index1 = 1 index2 = 246 index1 = 1 index2 = 247 index1 = 1 index2 = 248 index1 = 1 index2 = 249 index1 = 1 index2 = 250 index1 = 1 index2 = 251 index1 = 1 index2 = 252 index1 = 1 index2 = 253 index1 = 1 index2 = 254 index1 = 1 index2 = 255 index1 = 1 index2 = 256 index1 = 1 index2 = 257 index1 = 1 index2 = 258 index1 = 1 index2 = 259 index1 = 1 index2 = 260 index1 = 1 index2 = 261 index1 = 1 index2 = 262 index1 = 1 index2 = 263 index1 = 1 index2 = 264 index1...

Assertion failed.

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

index1 = 1 index2 = 2 index1 = 1 index2 = 3 index1 = 1 index2 = 4 index1 = 1 index2 = 5 index1 = 2 index2 = 3 index1 = 2 index2 = 4 index1 = 2 index2 = 5 index1 = 3 index2 = 4 index1 = 3 index2 = 5 index1 = 4 index2 = 5

Assertion failed.

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

index1 = 1 index2 = 2 index1 = 1 index2 = 3 index1 = 1 index2 = 4 index1 = 1 index2 = 5 index1 = 2 index2 = 3 index1 = 2 index2 = 4 index1 = 2 index2 = 5 index1 = 3 index2 = 4 index1 = 3 index2 = 5 index1 = 4 index2 = 5

Assertion failed.