Cody

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

Solution 1467288

Submitted on 20 Mar 2018 by Rikard Falkeborn
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|)')) )

ans = 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|)')) )

ans = 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|)')) )

ans = 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|)')) )

ans = Columns 1 through 14 1 2 3 4 6 7 8 9 11 12 13 14 16 17 Columns 15 through 28 18 19 21 22 23 24 26 27 28 29 31 32 33 34 Columns 29 through 42 36 37 38 39 41 42 43 44 46 47 48 49 51 52 Columns 43 through 56 53 54 56 57 58 59 61 62 63 64 66 67 68 69 Columns 57 through 70 71 72 73 74 76 77 78 79 81 82 83 84 86 87 Columns 71 through 84 88 89 91 92 93 94 96 97 98 99 101 102 103 104 Columns 85 through 98 106 107 108 109 111 112 113 114 116 117 118 119 121 122 Columns 99 through 112 123 124 126 127 128 129 131 132 133 134 136 137 138 139 Columns 113 through 126 141 142 143 144 146 147 148 149 151 152 153 154 156 157 Columns 127 through 140 158 159 161 162 163 164 166 167 168 169 171 172 173 174 Columns 141 through 154 176 177 178 179 181 182 183 184 186 187 188 189 191 192 Columns 155 through 168 193 194 196 197 198 199 201 202 203 204 206 207 208 209 Columns 169 through 182 211 212 213 214 216 217 218 219 221 222 223 224 226 227 Columns 183 through 196 228 229 231 232 233 234 236 237 238 239 241 242 243 244 Columns 197 through 210 246 247 248 249 251 252 253 254 256 257 258 259 261 262 Columns 211 through 224 263 264 266 267 268 269 271 272 273 274 276 277 278 279 Columns 225 through 238 281 282 283 284 286 287 288 289 291 292 293 294 296 297 Columns 239 through 252 298 299 301 302 303 304 306 307 308 309 311 312 313 314 Columns 253 through 266 316 317 318 319 321 322 323 324 326 327 328 329 331 332 Columns 267 through 280 333 334 336 337 338 339 341 342 343 344 346 347 348 349 Columns 281 through 294 351 352 353 354 356 357 358 359 361 362 363 364 366 367 Columns 295 through 308 368 369 371 372 373 374 376 377 378 379 381 382 383 384 Columns 309 through 322 386 387 388 389 391 392 393 394 396 397 398 399 401 402 Columns 323 through 336 403 404 406 407 408 409 411 412 413 414 416 417 418 419 Columns 337 through 350 421 422 423 424 426 427 428 429 431 432 433 434 436 437 Columns 351 through 364 438 439 441 442 443 444 446 447 448 449 451 452 453 454 Columns 365 through 378 456 457 458 459 461 462 463 464 466 467 468 469 471 472 Columns 379 through 392 473 474 476 477 478 479 481 482 483 484 486 487 488 489 Columns 393 through 406 491 492 493 494 496 497 498 499 501 502 503 504 506 507 Columns 407 through 420 508 509 511 512 513 514 516 517 518 519 521 522 523 524 Columns 421 through 434 526 527 528 529 531 532 533 534 536 537 538 539 541 542 Columns 435 through 448 543 544 546 547 548 549 551 552 553 554 556 557 558 559 Columns 449 through 462 561 562 563 564 566 567 568 569 571 572 573 574 576 577 Columns 463 through 476 578 579 581 582 583 584 586 587 588 589 591 592 593 594 Columns 477 through 490 596 597 598 599 601 602 603 604 606 607 608 609 611 612 Columns 491 through 504 613 614 616 617 618 619 621 622 623 624 626 627 628 629 Columns 505 through 518 631 632 633 634 636 637 638 639 641 642 643 644 646 647 Columns 519 through 532 648 649 651 652 653 654 656 657 658 659 661 662 663 664 Columns 533 through 546 666 667 668 669 671 672 673 674 676 677 678 679 681 682 Columns 547 through 560 683 684 686 687 688 689 691 692 693 694 696 697 698 699 Columns 561 through 574 701 702 703 704 706 707 708 709 711 712 713 714 716 717 Columns 575 through 588 718 719 721 722 723 724 726 727 728 729 731 732 733 734 Columns 589 through 602 736 737 738 739 741 742 743 744 746 747 748 749 751 752 Columns 603 through 616 753 754 756 757 758 759 761 762 763 764 766 767 768 769 Columns 617 through 630 771 772 773 774 776 777 778 779 781 782 783 784 786 787 Columns 631 through 644 788 789 791 792 793 794 796 797 798 799 801 802 803 804 Columns 645 through 658 806 807 808 809 811 812 813 814 816 817 818 819 821 822 Columns 659 through 672 823 824 826 827 828 829 831 832 833 834 836 837 838 839 Columns 673 through 686 841 842 843 844 846 847 848 849 851 852 853 854 856 857 Columns 687 through 700 858 859 861 862 863 864 866 867 868 869 871 872 873 874 Columns 701 through 714 876 877 878 879 881 882 883 884 886 887 888...