Cody

Solution 331944

Submitted on 10 Oct 2013 by Zikobrelli
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))

occurrence = 1 1 1 1 1 1 1 1 1 1 list = -46 -10 16 18 25 26 30 35 44 46 idx = Empty matrix: 1-by-0 a = 0 16 14 76 5 14 12 4 5 40 16 0 30 92 11 2 28 20 21 56 14 30 0 62 19 28 2 10 9 26 76 92 62 0 81 90 64 72 71 36 5 11 19 81 0 9 17 9 10 45 14 2 28 90 9 0 26 18 19 54 12 28 2 64 17 26 0 8 7 28 4 20 10 72 9 18 8 0 1 36 5 21 9 71 10 19 7 1 0 35 40 56 26 36 45 54 28 36 35 0 index1 = 9 8 index2 = 8 9 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))

occurrence = 1 1 1 1 1 1 1 1 1 1 list = Columns 1 through 8 -4681 -4538 -4028 -3288 -2230 -1829 1555 1949 Columns 9 through 10 2061 3235 idx = Empty matrix: 1-by-0 a = Columns 1 through 8 0 4843 506 6236 3785 6093 5583 1680 4843 0 5349 1393 1058 1250 740 6523 506 5349 0 6742 4291 6599 6089 1174 6236 1393 6742 0 2451 143 653 7916 3785 1058 4291 2451 0 2308 1798 5465 6093 1250 6599 143 2308 0 510 7773 5583 740 6089 653 1798 510 0 7263 1680 6523 1174 7916 5465 7773 7263 0 394 5237 112 6630 4179 6487 5977 1286 3384 1459 3890 2852 401 2709 2199 5064 Columns 9 through 10 394 3384 5237 1459 112 3890 6630 2852 4179 401 6487 2709 5977 2199 1286 5064 0 3778 3778 0 index1 = 9 3 index2 = 3 9 index2 = 9 index1 = 3

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

occurrence = 1 1 1 1 list = -10 -1 1 10 idx = Empty matrix: 1-by-0 a = 0 2 11 9 2 0 9 11 11 9 0 20 9 11 20 0 index1 = 2 1 index2 = 1 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))

occurrence = 1 2 1 1 list = -2000 0 1000 1001 idx = 2 c = 0 index = 1 5 index1 = 1 index2 = 5

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

occurrence = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 17 through 32 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 33 through 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 49 through 64 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 65 through 80 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 81 through 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 97 through 112 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 113 through 128 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 129 through 144 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 145 through 160 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 161 through 176 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 177 through 192 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 193 through 208 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 209 through 224 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 225 through 240 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 241 through 256 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 257 through 272 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 273 through 288 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 289 through 304 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 305 through 320 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 321 through 336 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 337 through 352 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 353 through 368 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 369 through 384 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 385 through 400 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 401 through 416 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 417 through 432 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 433 through 448 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 449 through 464 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 465 through 480 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 481 through 496 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 497 through 512 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 513 through 528 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 529 through 544 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 545 through 560 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 561 through 576 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 577 through 592 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 593 through 608 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 609 through 624 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 625 through 640 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 641 through 656 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 657 through 672 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 673 through 688 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 689 through 704 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 705 through 720 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 721 through 736 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 737 through 752 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 753 through 768 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 769 through 784 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 785 through 800 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 801 through 816 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 817 through 832 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 833 through 848 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 849 through 864 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 865 through 880 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 881 through 896 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 897 through 912 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 913 through 928 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 929 through 944 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 945 through 960 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 961 through 976 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 977 through 992 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Columns 993 through 1001 1 1 1 1 1 1 1 1 1 list = 1.0e+03 * Columns 1 through 10 0.0005 0.0010 0.0020 0.0030 0.0040 0.0050 0.0060 0.0070 0.0080 0.0090 Columns 11 through 20 0.0100 0.0110 0.0120 0.0130 0.0140 0.0150 0.0160 0.0170 0.0180 0.0190 Columns 21 through 30 0.0200 0.0210 0.0220 0.0230 0.0240 0.0250 0.0260 0.0270 0.0280 0.0290 Columns 31 through 40 0.0300 0.0310 0.0320 0.0330 0.0340 0.0350 0.0360 0.0370 0.0380 0.0390 Columns 41 through 50 0.0400 0.0410 0.0420 0.0430 0.0440 0.0450 0.0460 0.0470 0.0480 0.0490 Columns 51 through 60 0.0500 0.0510 0.0520 0.0530 0.0540 0.0550 0.0560 0.0570 0.0580 0.0590 Columns 61 through 70 0.0600 0.0610 0.0620 0.0630 0.0640 0.0650 0.0660 0.0670 0.0680 0.0690 Columns 71 through 80 0.0700 0.0710 0.0720 0.0730 0.0740 0.0750 0.0760 0.0770 0.0780 0.0790 Columns 81 through 90 0.0800 0.0810 0.0820 0.0830 0.0840 0.0850 0.0860 0.0870 0.0880 0.0890 Columns 91 through 100 0.0900 0.0910 0.0920 0.0930 0.0940 0.0950 0.0960 0.0970 0.0980 0.0990 Columns 101 through 110 0.1000 0.1010 0.1020 0.1030 0.1040 0.1050 0.1060 0.1070 0.1080 0.1090 Columns 111 through 120 0.1100 0.1110 0.1120 0.1130 0.1140 0.1150 0.1160 0.1170 0.1180 0.1190 Columns 121 through 130 0.1200 0.1210 0.1220 0.1230 0.1240 0.1250 0.1260 0.1270 0.1280 0.1290 Columns 131 through 140 0.1300 0.1310 0.1320 0.1330 0.1340 0.1350 0.1360 0.1370 0.1380 0.1390 Columns 141 through 150 0.1400 0.1410 0.1420 0.1430 0.1440 0.1450 0.1460 0.1470 0.1480 0.1490 Columns 151 through 160 0.1500 0.1510 0.1520 0.1530 0.1540 0.1550 0.1560 0.1570 0.1580 0.1590 Columns 161 through 170 0.1600 0.1610 0.1620 0.1630 0.1640 0.1650 0.1660 0.1670 0.1680 0.1690 Columns 171 through 180 0.1700 0.1710 0.1720 0.1730 0.1740 0.1750 0.1760 0.1770 0.1780 0.1790 Colu...

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

occurrence = 1 1 1 1 1 list = 212 217 312 508 847 idx = Empty matrix: 1-by-0 a = 0 630 339 535 635 630 0 291 95 5 339 291 0 196 296 535 95 196 0 100 635 5 296 100 0 index1 = 5 2 index2 = 2 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))

occurrence = 1 1 1 1 1 list = 1702 10001 60048 60601 61802 idx = Empty matrix: 1-by-0 a = 0 1754 58346 553 50047 1754 0 60100 1201 51801 58346 60100 0 58899 8299 553 1201 58899 0 50600 50047 51801 8299 50600 0 index1 = 4 1 index2 = 1 4 index2 = 4 index1 = 1

Suggested Problems

More from this Author95