Cody

# Problem 801. Construct an index vector from two input vectors in vectorized fashion

Solution 2050462

Submitted on 8 Dec 2019 by Asif Newaz
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
x1 = 1; x2 = 5; y_correct = [1:5]; assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

lo = 1 hi = 5 m = 1 len = 5 n = 5 idx = 1 1 1 1 1 idx = 1 1 1 1 1 len = 6 idx = 1 1 1 1 1 idx = 1 2 3 4 5 y = 1 2 3 4 5

2   Pass
x1 = [7 10 13]; x2 = [9 12 15]; y_correct = [7:15]; assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

lo = 7 10 13 hi = 9 12 15 m = 3 len = 3 3 3 n = 9 idx = 1 1 1 1 1 1 1 1 1 idx = 7 1 1 1 1 1 1 1 1 len = 4 3 3 idx = 7 1 1 1 1 1 1 1 1 idx = 7 8 9 10 11 12 13 14 15 y = 7 8 9 10 11 12 13 14 15

3   Pass
x1 = [13 7]; x2 = [15 9]; y_correct = [13 14 15 7 8 9]; assert(isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

lo = 13 7 hi = 15 9 m = 2 len = 3 3 n = 6 idx = 1 1 1 1 1 1 idx = 13 1 1 1 1 1 len = 4 3 idx = 13 1 1 -8 1 1 idx = 13 14 15 7 8 9 y = 13 14 15 7 8 9

4   Pass
x1=[1:5:5000];x2=[4:5:5000];y_correct=setdiff([1:5000],[5:5:5000]); assert( isequal(interleaved_idx(x1,x2),y_correct) && isempty(regexp(evalc('type interleaved_idx'),'(eval|for|while|)')) )

lo = Columns 1 through 15 1 6 11 16 21 26 31 36 41 46 51 56 61 66 71 Columns 16 through 30 76 81 86 91 96 101 106 111 116 121 126 131 136 141 146 Columns 31 through 45 151 156 161 166 171 176 181 186 191 196 201 206 211 216 221 Columns 46 through 60 226 231 236 241 246 251 256 261 266 271 276 281 286 291 296 Columns 61 through 75 301 306 311 316 321 326 331 336 341 346 351 356 361 366 371 Columns 76 through 90 376 381 386 391 396 401 406 411 416 421 426 431 436 441 446 Columns 91 through 105 451 456 461 466 471 476 481 486 491 496 501 506 511 516 521 Columns 106 through 120 526 531 536 541 546 551 556 561 566 571 576 581 586 591 596 Columns 121 through 135 601 606 611 616 621 626 631 636 641 646 651 656 661 666 671 Columns 136 through 150 676 681 686 691 696 701 706 711 716 721 726 731 736 741 746 Columns 151 through 165 751 756 761 766 771 776 781 786 791 796 801 806 811 816 821 Columns 166 through 180 826 831 836 841 846 851 856 861 866 871 876 881 886 891 896 Columns 181 through 195 901 906 911 916 921 926 931 936 941 946 951 956 961 966 971 Columns 196 through 210 976 981 986 991 996 1001 1006 1011 1016 1021 1026 1031 1036 1041 1046 Columns 211 through 225 1051 1056 1061 1066 1071 1076 1081 1086 1091 1096 1101 1106 1111 1116 1121 Columns 226 through 240 1126 1131 1136 1141 1146 1151 1156 1161 1166 1171 1176 1181 1186 1191 1196 Columns 241 through 255 1201 1206 1211 1216 1221 1226 1231 1236 1241 1246 1251 1256 1261 1266 1271 Columns 256 through 270 1276 1281 1286 1291 1296 1301 1306 1311 1316 1321 1326 1331 1336 1341 1346 Columns 271 through 285 1351 1356 1361 1366 1371 1376 1381 1386 1391 1396 1401 1406 1411 1416 1421 Columns 286 through 300 1426 1431 1436 1441 1446 1451 1456 1461 1466 1471 1476 1481 1486 1491 1496 Columns 301 through 315 1501 1506 1511 1516 1521 1526 1531 1536 1541 1546 1551 1556 1561 1566 1571 Columns 316 through 330 1576 1581 1586 1591 1596 1601 1606 1611 1616 1621 1626 1631 1636 1641 1646 Columns 331 through 345 1651 1656 1661 1666 1671 1676 1681 1686 1691 1696 1701 1706 1711 1716 1721 Columns 346 through 360 1726 1731 1736 1741 1746 1751 1756 1761 1766 1771 1776 1781 1786 1791 1796 Columns 361 through 375 1801 1806 1811 1816 1821 1826 1831 1836 1841 1846 1851 1856 1861 1866 1871 Columns 376 through 390 1876 1881 1886 1891 1896 1901 1906 1911 1916 1921 1926 1931 1936 1941 1946 Columns 391 through 405 1951 1956 1961 1966 1971 1976 1981 1986 1991 1996 2001 2006 2011 2016 2021 Columns 406 through 420 2026 2031 2036 2041 2046 2051 2056 2061 2066 2071 2076 2081 2086 2091 2096 Columns 421 through 435 2101 2106 2111 2116 2121 2126 2131 2136 2141 2146 2151 2156 2161 2166 2171 Columns 436 through 450 2176 2181 2186 2191 2196 2201 2206 2211 2216 2221 2226 2231 2236 2241 2246 Columns 451 through 465 2251 2256 2261 2266 2271 2276 2281 2286 2291 2296 2301 2306 2311 2316 2321 Columns 466 through 480 2326 2331 2336 2341 2346 2351 2356 2361 2366 2371 2376 2381 2386 2391 2396 Columns 481 through 495 2401 2406 2411 2416 2421 2426 2431 2436 2441 2446 2451 2456 2461 2466 2471 Columns 496 through 510 2476 2481 2486 2491 2496 2501 2506 2511 2516 2521 2526 2531 2536 2541 2546 Columns 511 through 525 2551 2556 2561 2566 2571 2576 2581 2586 2591 2596 2601 2606 2611 2616 2621 Columns 526 through 540 2626 2631 2636 2641 2646 2651 2656 2661 2666 2671 2676 2681 2686 2691 2696 Columns 541 through 555 2701 2706 2711 2716 2721 2726 2731 2736 2741 2746 2751 2756 2761 2766 2771 Columns 556 through 570 2776 2781 2786 2791 2796 2801 2806 2811 2816 2821 2826 2831 2836 2841 2846 Columns 571 through 585 2851 2856 2861 2866 2871 2876 2881 2886 2891 2896 2901 2906 2911 2916 2921 Columns 586 through 600 2926 2931 2936 2941 2946 2951 2956 2961 2966 2971 2976 2981 2986 2991 2996 Columns 601 through 615 3001 3006 3011 3016 3021 3026 3031 3036 3041 3046 3051 3056 3061 3066 3071 Columns 616 through 630 3076 3081 3086 3091 3096 3101 3106 3111 3116 3121 3126 3131 3136 3141 3146 Columns 631 through 645 3151 3156 3161 3166 3171 3176 3181 3186 3191 3196 3201 3206 3211 3216 3221 Columns 646 through 660 3226 3231 3236 3241 3246 3251 3256 3261 3266 3271 3276 3281 3286 3291 3296 Columns 661 through 675 3301 3306 3311 3316 3321 3326 3331 3336 3341 3346 3351 3356 3361 3366 3371 Columns 676 through 690 3376 3381 3386 3391 3396 3401 3406 3411 3416 3421 3426 3431 3436 3441 3446 Columns 691 through 705 3451 3456 3461 3466 3471 3476 3481 3486 3491 3496 3501 3506 3511 3516 3521 Columns 706 through 720 3526 3531 3536 3541 3546 3551 3556 3561 3566 3571 3576 3581 3586 ...