Cody

Solution 1942910

Submitted on 19 Sep 2019 at 14:58 by Augusto Mazzei
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
assert(isempty(mindiag([])))

y = 1×0 empty double row vector

2   Pass
x = randi(100); assert(isequal(mindiag(x),x))

y = 68

3   Pass
x = randi(100,100,1); assert(isequal(mindiag(x),x(end:-1:1)'))

y = Columns 1 through 29 20 29 66 21 8 9 97 85 43 62 13 62 83 48 94 18 30 64 8 62 47 71 21 35 27 94 83 57 45 Columns 30 through 58 33 100 90 43 27 73 44 61 28 20 53 18 15 93 9 68 55 61 62 41 85 33 81 37 57 88 88 22 5 Columns 59 through 87 31 39 31 15 16 30 60 93 74 79 66 17 69 32 9 74 42 26 12 60 10 92 61 25 91 42 56 5 7 Columns 88 through 100 79 39 93 37 67 12 24 35 18 88 4 20 53

4   Pass
x = randi(100,1,100); assert(isequal(mindiag(x),x))

y = Columns 1 through 29 22 59 4 33 60 25 76 44 21 12 16 59 20 94 22 5 99 79 5 44 15 49 67 47 51 17 71 40 73 Columns 30 through 58 82 39 43 47 12 89 12 48 95 4 14 27 23 72 10 21 79 17 32 66 83 42 35 7 55 68 45 99 30 Columns 59 through 87 76 87 99 25 78 5 20 16 96 20 3 74 8 74 79 39 5 27 73 78 16 39 68 40 96 81 34 100 81 Columns 88 through 100 34 56 6 13 10 11 27 15 12 7 18 22 81

5   Pass
x = eye(2); assert(isequal(mindiag(x),[0 1 0]))

y = 0 1 0

6   Pass
x = magic(3); assert(isequal(mindiag(x),[4 3 2 1 6]))

y = 4 3 2 1 6

7   Pass
x = flipud(hankel(1:1000)); assert(isequal(mindiag(x),[1:1000,zeros(1,1000-1)]))

y = Columns 1 through 14 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Columns 15 through 28 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 29 through 42 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Columns 43 through 56 43 44 45 46 47 48 49 50 51 52 53 54 55 56 Columns 57 through 70 57 58 59 60 61 62 63 64 65 66 67 68 69 70 Columns 71 through 84 71 72 73 74 75 76 77 78 79 80 81 82 83 84 Columns 85 through 98 85 86 87 88 89 90 91 92 93 94 95 96 97 98 Columns 99 through 112 99 100 101 102 103 104 105 106 107 108 109 110 111 112 Columns 113 through 126 113 114 115 116 117 118 119 120 121 122 123 124 125 126 Columns 127 through 140 127 128 129 130 131 132 133 134 135 136 137 138 139 140 Columns 141 through 154 141 142 143 144 145 146 147 148 149 150 151 152 153 154 Columns 155 through 168 155 156 157 158 159 160 161 162 163 164 165 166 167 168 Columns 169 through 182 169 170 171 172 173 174 175 176 177 178 179 180 181 182 Columns 183 through 196 183 184 185 186 187 188 189 190 191 192 193 194 195 196 Columns 197 through 210 197 198 199 200 201 202 203 204 205 206 207 208 209 210 Columns 211 through 224 211 212 213 214 215 216 217 218 219 220 221 222 223 224 Columns 225 through 238 225 226 227 228 229 230 231 232 233 234 235 236 237 238 Columns 239 through 252 239 240 241 242 243 244 245 246 247 248 249 250 251 252 Columns 253 through 266 253 254 255 256 257 258 259 260 261 262 263 264 265 266 Columns 267 through 280 267 268 269 270 271 272 273 274 275 276 277 278 279 280 Columns 281 through 294 281 282 283 284 285 286 287 288 289 290 291 292 293 294 Columns 295 through 308 295 296 297 298 299 300 301 302 303 304 305 306 307 308 Columns 309 through 322 309 310 311 312 313 314 315 316 317 318 319 320 321 322 Columns 323 through 336 323 324 325 326 327 328 329 330 331 332 333 334 335 336 Columns 337 through 350 337 338 339 340 341 342 343 344 345 346 347 348 349 350 Columns 351 through 364 351 352 353 354 355 356 357 358 359 360 361 362 363 364 Columns 365 through 378 365 366 367 368 369 370 371 372 373 374 375 376 377 378 Columns 379 through 392 379 380 381 382 383 384 385 386 387 388 389 390 391 392 Columns 393 through 406 393 394 395 396 397 398 399 400 401 402 403 404 405 406 Columns 407 through 420 407 408 409 410 411 412 413 414 415 416 417 418 419 420 Columns 421 through 434 421 422 423 424 425 426 427 428 429 430 431 432 433 434 Columns 435 through 448 435 436 437 438 439 440 441 442 443 444 445 446 447 448 Columns 449 through 462 449 450 451 452 453 454 455 456 457 458 459 460 461 462 Columns 463 through 476 463 464 465 466 467 468 469 470 471 472 473 474 475 476 Columns 477 through 490 477 478 479 480 481 482 483 484 485 486 487 488 489 490 Columns 491 through 504 491 492 493 494 495 496 497 498 499 500 501 502 503 504 Columns 505 through 518 505 506 507 508 509 510 511 512 513 514 515 516 517 518 Columns 519 through 532 519 520 521 522 523 524 525 526 527 528 529 530 531 532 Columns 533 through 546 533 534 535 536 537 538 539 540 541 542 543 544 545 546 Columns 547 through 560 547 548 549 550 551 552 553 554 555 556 557 558 559 560 Columns 561 through 574 561 562 563 564 565 566 567 568 569 570 571 572 573 574 Columns 575 through 588 575 576 577 578 579 580 581 582 583 584 585 586 587 588 Columns 589 through 602 589 590 591 592 593 594 595 596 597 598 599 600 601 602 Columns 603 through 616 603 604 605 606 607 608 609 610 611 612 613 614 615 616 Columns 617 through 630 617 618 619 620 621 622 623 624 625 626 627 628 629 630 Columns 631 through 644 631 632 633 634 635 636 637 638 639 640 641 642 643 644 Columns 645 through 658 645 646 647 648 649 650 651 652 653 654 655 656 657 658 Columns 659 through 672 659 660 661 662 663 664 665 666 667 668 669 670 671 672 Columns 673 through 686 673 674 675 676 677 678 679 680 681 682 683 684 685 686 Columns 687 through 700 687 688 689 690 691 692 693 694 695 696 697 698 699 700 Columns 701 through 714 701 702 703 704 705 706 707 708 709 710 711 ...

8   Pass
x = toeplitz(1:1000); assert(isequal(mindiag(x),[1000:-1:1,2:1000]))

y = Columns 1 through 14 1000 999 998 997 996 995 994 993 992 991 990 989 988 987 Columns 15 through 28 986 985 984 983 982 981 980 979 978 977 976 975 974 973 Columns 29 through 42 972 971 970 969 968 967 966 965 964 963 962 961 960 959 Columns 43 through 56 958 957 956 955 954 953 952 951 950 949 948 947 946 945 Columns 57 through 70 944 943 942 941 940 939 938 937 936 935 934 933 932 931 Columns 71 through 84 930 929 928 927 926 925 924 923 922 921 920 919 918 917 Columns 85 through 98 916 915 914 913 912 911 910 909 908 907 906 905 904 903 Columns 99 through 112 902 901 900 899 898 897 896 895 894 893 892 891 890 889 Columns 113 through 126 888 887 886 885 884 883 882 881 880 879 878 877 876 875 Columns 127 through 140 874 873 872 871 870 869 868 867 866 865 864 863 862 861 Columns 141 through 154 860 859 858 857 856 855 854 853 852 851 850 849 848 847 Columns 155 through 168 846 845 844 843 842 841 840 839 838 837 836 835 834 833 Columns 169 through 182 832 831 830 829 828 827 826 825 824 823 822 821 820 819 Columns 183 through 196 818 817 816 815 814 813 812 811 810 809 808 807 806 805 Columns 197 through 210 804 803 802 801 800 799 798 797 796 795 794 793 792 791 Columns 211 through 224 790 789 788 787 786 785 784 783 782 781 780 779 778 777 Columns 225 through 238 776 775 774 773 772 771 770 769 768 767 766 765 764 763 Columns 239 through 252 762 761 760 759 758 757 756 755 754 753 752 751 750 749 Columns 253 through 266 748 747 746 745 744 743 742 741 740 739 738 737 736 735 Columns 267 through 280 734 733 732 731 730 729 728 727 726 725 724 723 722 721 Columns 281 through 294 720 719 718 717 716 715 714 713 712 711 710 709 708 707 Columns 295 through 308 706 705 704 703 702 701 700 699 698 697 696 695 694 693 Columns 309 through 322 692 691 690 689 688 687 686 685 684 683 682 681 680 679 Columns 323 through 336 678 677 676 675 674 673 672 671 670 669 668 667 666 665 Columns 337 through 350 664 663 662 661 660 659 658 657 656 655 654 653 652 651 Columns 351 through 364 650 649 648 647 646 645 644 643 642 641 640 639 638 637 Columns 365 through 378 636 635 634 633 632 631 630 629 628 627 626 625 624 623 Columns 379 through 392 622 621 620 619 618 617 616 615 614 613 612 611 610 609 Columns 393 through 406 608 607 606 605 604 603 602 601 600 599 598 597 596 595 Columns 407 through 420 594 593 592 591 590 589 588 587 586 585 584 583 582 581 Columns 421 through 434 580 579 578 577 576 575 574 573 572 571 570 569 568 567 Columns 435 through 448 566 565 564 563 562 561 560 559 558 557 556 555 554 553 Columns 449 through 462 552 551 550 549 548 547 546 545 544 543 542 541 540 539 Columns 463 through 476 538 537 536 535 534 533 532 531 530 529 528 527 526 525 Columns 477 through 490 524 523 522 521 520 519 518 517 516 515 514 513 512 511 Columns 491 through 504 510 509 508 507 506 505 504 503 502 501 500 499 498 497 Columns 505 through 518 496 495 494 493 492 491 490 489 488 487 486 485 484 483 Columns 519 through 532 482 481 480 479 478 477 476 475 474 473 472 471 470 469 Columns 533 through 546 468 467 466 465 464 463 462 461 460 459 458 457 456 455 Columns 547 through 560 454 453 452 451 450 449 448 447 446 445 444 443 442 441 Columns 561 through 574 440 439 438 437 436 435 434 433 432 431 430 429 428 427 Columns 575 through 588 426 425 424 423 422 421 420 419 418 417 416 415 414 413 Columns 589 through 602 412 411 410 409 408 407 406 405 404 403 402 401 400 399 Columns 603 through 616 398 397 396 395 394 393 392 391 390 389 388 387 386 385 Columns 617 through 630 384 383 382 381 380 379 378 377 376 375 374 373 372 371 Columns 631 through 644 370 369 368 367 366 365 364 363 362 361 360 359 358 357 Columns 645 through 658 356 355 354 353 352 351 350 349 348 347 346 345 344 343 Columns 659 through 672 342 341 340 339 338 337 336 335 334 333 332 331 330 329 Columns 673 through 686 328 327 326 325 324 323 322 321 320 319 318 317 316 315 Columns 687 through 700 314 313 312 311 310 309 308 307 306 305 304 303 302 301 Columns 701 through 714 300 299 298 297 296 295 294 293 292 291 290 ...

9   Pass
N = randi(1000); x = fliplr(toeplitz(1:N)); y = ones(1,2*N-1); y(2:2:end) = 2; assert(isequal(mindiag(x),y))

y = Columns 1 through 29 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 30 through 58 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 59 through 87 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 88 through 116 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 117 through 145 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 146 through 174 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 175 through 203 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 204 through 232 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 233 through 261 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 262 through 290 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 291 through 319 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 320 through 348 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 349 through 377 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 378 through 406 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 407 through 435 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 436 through 464 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 465 through 493 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 494 through 522 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 523 through 551 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 552 through 580 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 581 through 609 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 610 through 638 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 639 through 667 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 668 through 696 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 697 through 725 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 726 through 754 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 755 through 783 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 784 through 812 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 813 through 841 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 842 through 870 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 871 through 899 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 900 through 928 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 929 through 957 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 958 through 986 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 987 through 1015 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 1016 through 1044 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 1045 through 1073 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 1074 through 1102 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 1103 through 1131 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 1132 through 1160 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 1161 through 1189 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 1190 through 1218 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 1219 through 1247 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 1248 through 1276 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 1277 through 1305 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 1306 through 1334 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 1335 through 1363 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 1364 through 1392 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 Columns 1393 through 1421 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 Columns 1422 through 1450...

10   Pass
x = magic(10); x = x(:,1:3); assert(isequal(mindiag(x),[11 10 12 6 5 24 76 4 19 80 7 1]))

y = 11 10 12 6 5 24 76 4 19 80 7 1

11   Pass
x = hankel(-4:0,0:-2:-16); assert(isequal(mindiag(x),[0 -2 -4 -6 -8 -10 -12 -14 -16 -14 -12 -10 -8]))

y = 0 -2 -4 -6 -8 -10 -12 -14 -16 -14 -12 -10 -8