Cody

Solution 1823079

Submitted on 22 May 2019 by Anshil Kumar
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))

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

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))

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

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

s1 = 1 2 2 s = 1 2 2 s1 = 1 3 11 s1 = 1 4 9 s1 = 2 3 9 s1 = 2 4 11 s1 = 3 4 20 index1 = 1 index2 = 2

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

s1 = 1 2 1000 s = 1 2 1000 s1 = 1 3 2000 s1 = 1 4 1001 s1 = 1 5 0 s = 1 5 0 s1 = 2 3 3000 s1 = 2 4 1 s1 = 2 5 1000 s1 = 3 4 3001 s1 = 3 5 2000 s1 = 4 5 1001 index1 = 1 index2 = 5

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

s1 = 1 2 1 s = 1 2 1 s1 = 1 3 2 s1 = 1 4 3 s1 = 1 5 4 s1 = 1 6 5 s1 = 1 7 6 s1 = 1 8 7 s1 = 1 9 8 s1 = 1 10 9 s1 = 1 11 10 s1 = 1 12 11 s1 = 1 13 12 s1 = 1 14 13 s1 = 1 15 14 s1 = 1 16 15 s1 = 1 17 16 s1 = 1 18 17 s1 = 1 19 18 s1 = 1 20 19 s1 = 1 21 20 s1 = 1 22 21 s1 = 1 23 22 s1 = 1 24 23 s1 = 1 25 24 s1 = 1 26 25 s1 = 1 27 26 s1 = 1 28 27 s1 = 1 29 28 s1 = 1 30 29 s1 = 1 31 30 s1 = 1 32 31 s1 = 1 33 32 s1 = 1 34 33 s1 = 1 35 34 s1 = 1 36 35 s1 = 1 37 36 s1 = 1 38 37 s1 = 1 39 38 s1 = 1 40 39 s1 = 1 41 40 s1 = 1 42 41 s1 = 1 43 42 s1 = 1 44 43 s1 = 1 45 44 s1 = 1 46 45 s1 = 1 47 46 s1 = 1 48 47 s1 = 1 49 48 s1 = 1 50 49 s1 = 1 51 50 s1 = 1 52 51 s1 = 1 53 52 s1 = 1 54 53 s1 = 1 55 54 s1 = 1 56 55 s1 = 1 57 56 s1 = 1 58 57 s1 = 1 59 58 s1 = 1 60 59 s1 = 1 61 60 s1 = 1 62 61 s1 = 1 63 62 s1 = 1 64 63 s1 = 1 65 64 s1 = 1 66 65 s1 = 1 67 66 s1 = 1 68 67 s1 = 1 69 68 s1 = 1 70 69 s1 = 1 71 70 s1 = 1 72 71 s1 = 1 73 72 s1 = 1 74 73 s1 = 1 75 74 s1 = 1 76 75 s1 = 1 77 76 s1 = 1 78 77 s1 = 1 79 78 s1 = 1 80 79 s1 = 1 81 80 s1 = 1 82 81 s1 = 1 83 82 s1 = 1 84 83 s1 = 1 85 84 s1 = 1 86 85 s1 = 1 87 86 s1 = 1 88 87 s1 = 1 89 88 s1 = 1 90 89 s1 = 1 91 90 s1 = 1 92 91 s1 = 1 93 92 s1 = 1 94 93 s1 = 1 95 94 s1 = 1 96 95 s1 = 1 97 96 s1 = 1 98 97 s1 = 1 99 98 s1 = 1 100 99 s1 = 1 101 100 s1 = 1 102 101 s1 = 1 103 102 s1 = 1 104 103 s1 = 1 105 104 s1 = 1 106 105 s1 = 1 107 106 s1 = 1 108 107 s1 = 1 109 108 s1 = 1 110 109 s1 = 1 111 110 s1 = 1 112 111 s1 = 1 113 112 s1 = 1 114 113 s1 = 1 115 114 s1 = 1 116 115 s1 = 1 117 116 s1 = 1 118 117 s1 = 1 119 118 s1 = 1 120 119 s1 = 1 121 120 s1 = 1 122 121 s1 = 1 123 122 s1 = 1 124 123 s1 = 1 125 124 s1 = 1 126 125 s1 = 1 127 126 s1 = 1 128 127 s1 = 1 129 128 s1 = 1 130 129 s1 = 1 131 130 s1 = 1 132 131 s1 = 1 133 132 s1 = 1 134 133 s1 = 1 135 134 s1 = 1 136 135 s1 = 1 137 136 s1 = 1 138 137 s1 = 1 139 138 s1 = 1 140 139 s1 = 1 141 140 s1 = 1 142 141 s1 = 1 143 142 s1 = 1 144 143 s1 = 1 145 144 s1 = 1 146 145 s1 = 1 147 146 s1 = 1 148 147 s1 = 1 149 148 s1 = 1 150 149 s1 = 1 151 150 s1 = 1 152 151 s1 = 1 153 152 s1 = 1 154 153 s1 = 1 155 154 s1 = 1 156 155 s1 = 1 157 156 s1 = 1 158 157 s1 = 1 159 158 s1 = 1 160 159 s1 = 1 161 160 s1 = 1 162 161 s1 = 1 163 162 s1 = 1 164 163 s1 = 1 165 164 s1 = 1 166 165 s1 = 1 167 166 s1 = 1 168 167 s1 = 1 169 168 s1 = 1 170 169 s1 = 1 171 170 s1 = 1 172 171 s1 = 1 173 172 s1 = 1 174 173 s1 = 1 175 174 s1 = 1 176 175 s1 = 1 177 176 s1 = 1 178 177 s1 = 1 179 178 s1 = 1 180 179 s1 = 1 181 180 s1 = 1 182 181 s1 = 1 183 182 s1 = 1 184 183 s1 = 1 185 184 s1 = 1 186 185 s1 = 1 187 186 s1 = 1 188 187 s1 = 1 189 188 s1 = 1 190 189 s1 = 1 191 190 s1 = 1 192 191 s1 = 1 193 192 s1 = 1 194 193 s1 = 1 195 194 s1 = 1 196 195 s1 = 1 197 196 s1 = 1 198 197 s1 = 1 199 198 s1 = 1 200 199 s1 = 1 201 200 s1 = 1 202 201 s1 = 1 203 202 s1 = 1 204 203 s1 = 1 205 204 s1 = 1 206 205 s1 = 1 207 206 s1 = 1 208 207 s1 = 1 209 208 s1 = 1 210 209 s1 = 1 211 210 s1 = 1 212 211 s1 = 1 213 212 s1 = 1 214 213 s1 = 1 215 214 s1 = 1 216 215 s1 = 1 217 216 s1 = 1 218 217 s1 = 1 219 218 s1 = 1 220 219 s1 = 1 221 220 s1 = 1 222 221 s1 = 1 223 222 s1 = 1 224 223 s1 = 1 225 224 s1 = 1 226 225 s1 = 1 227 226 s1 = 1 228 227 s1 = 1 229 228 s1 = 1 230 229 s1 = 1 231 230 s1 = 1 232 231 s1 = 1 233 232 s1 = 1 234 233 s1 = 1 235 234 s1 = 1 236 235 s1 = 1 237 236 s1 = 1 238 237 s1 = 1 239 238 s1 = 1 240 239 s1 = 1 241 240 s1 = 1 242 241 s1 = 1 243 242 s1 = 1 244 243 s1 = 1 245 244 s1 = 1 246 245 s1 = 1 247 246 s1 = 1 248 247 s1 = 1 249 248 s1 = 1 250 249 s1 = 1 251 250 s1 = 1 252 251 s1 = 1 253 252 s1 = 1 254 253 s1 = 1 255 254 s1 = 1 256 255 s1 = 1 257 256 s1 = 1 258 257 s1 = 1 259 258 s1 = 1 260 259 s1 = 1 261 260 s1 = 1 262 261 s1 = 1 263 262 s1 = 1 264 263 s1 = 1 265 264 s1 = 1 266 265 s1 = 1 267 266 s1 = 1 268 267 s1 = 1 269 268 s1 = 1 270 269 s1 = 1 271 270 s1 = 1 272 271 s1 = 1 273 272 s1 = 1 274 273 s1 = 1 275 274 s1 = 1 276 275 s1 = 1 277 276 s1 = 1 278 277 s1 = 1 279 278 s1 = 1 280 279 s1 = 1 281 280 s1 = 1 282 281 s1 = 1 283 282 s1 = 1 284 283 s1 = 1 285 284 s1 = 1 286 285 s1 = 1 287 286 s1 = 1 288 287 s1 = 1 289 288 s1 = 1 290 289 s1 = 1 291 290 s1 = 1 292 291 s1 = 1 293 292 s1 = 1 294 293 s1 = 1 295 294 s1 = 1 296 295 s1 = 1 297 296 s1 = 1 298 297 s1 = 1 299 298 s1 = 1 300 299 s1 = 1 301 300 s1 = 1 302 301 s1 = 1 303 302 s1 = 1 304 303 s1 = 1 305 304 s1 = 1 306 305 s1 = 1 307 306 s1 = 1 308 307 s1 = 1 309 308 s1 = 1 310 309 s1 = 1 311 310 s1 = 1 312 311 s1 = 1 313 312 s1 = 1 314 313 s1 = 1 315 314 s1 = 1 316 315 s1 = 1 317 316 s1 = 1 318 317 s1 = 1 319 318 s1 = 1 320 319 s1 = 1 321 320 s1 = 1 322 321 s1 = 1 323 322 s1 = 1 324 323 s1 = 1 325 324 s1 = 1 326 325 s1 = 1 327 326 s1 = 1 328 327 s1 = 1 329 328 s1 = 1 330 329 s1 = 1 331 330 s1 = 1 332 331 s1 = 1 333 332 s1 = 1 334 333 s1 = 1 335 334 s1 = 1 336 335 s1 = 1 337 336 s1 = 1 338 337 s1 = 1 339 338 s1 = 1 340 339 s1 = 1 341 340 s1 = 1 342 341 s1 = 1 343 342 s1 = 1 344 343 s1 = 1 345 344 s1 = 1 346 345 s1 = 1 347 346 s1 = 1 348 347 s1 = 1 349 348 s1 = 1 350 349 s1 = 1 351 350 s1 = 1 352 351 s1 = 1 353 352 s1 = 1 354 353 s1 = 1 355 354 s1 = 1 356 355 s1 = 1 357 356 s1 = 1 358 357 s1 = 1 359 358 s1 = 1 360 359 s1 = 1 361 360 s1 = 1 362 361 s1 = 1 363 362 s1 = 1 364 363 s1 = 1 365 364 s1 = 1 366 365 s1 = 1 367 366 s1 = 1 368 367 s1 = 1 369 368 s1 = 1 370 369 s1 = ...

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

s1 = 1 2 630 s = 1 2 630 s1 = 1 3 339 s = 1 3 339 s1 = 1 4 535 s1 = 1 5 635 s1 = 2 3 291 s = 2 3 291 s1 = 2 4 95 s = 2 4 95 s1 = 2 5 5 s = 2 5 5 s1 = 3 4 196 s1 = 3 5 296 s1 = 4 5 100 index1 = 2 index2 = 5

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

s1 = 1 2 1754 s = 1 2 1754 s1 = 1 3 58346 s1 = 1 4 553 s = 1 4 553 s1 = 1 5 50047 s1 = 2 3 60100 s1 = 2 4 1201 s1 = 2 5 51801 s1 = 3 4 58899 s1 = 3 5 8299 s1 = 4 5 50600 index1 = 1 index2 = 4