Cody

# Problem 412. Back to basics 22 - Rotate a matrix

Solution 661858

Submitted on 27 Apr 2015 by Li Yjie
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
%% x = [1 2; 3 4]; y_correct = [2 4; 1 3]; assert(isequal(rotate(x),y_correct))

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

2   Fail
%% x = [1 2 3; 4 5 6; 7 8 9]; y_correct = [ 3 6 9; 2 5 8; 1 4 7]; assert(isequal(rotate(x),y_correct))

b = 1 b = 2 b = 3 b = 4 b = 5 b = 6 b = 7 b = 8 b = 9 b = 10 b = 11 b = 12 b = 13 b = 14 b = 15 b = 16 b = 17 b = 18 b = 19 b = 20 b = 21 b = 22 b = 23 b = 24 b = 25 b = 26 b = 27 b = 28 b = 29 b = 30 b = 31 b = 32 b = 33 b = 34 b = 35 b = 36 b = 37 b = 38 b = 39 b = 40 b = 41 b = 42 b = 43 b = 44 b = 45 b = 46 b = 47 b = 48 b = 49 b = 50 b = 51 b = 52 b = 53 b = 54 b = 55 b = 56 b = 57 b = 58 b = 59 b = 60 b = 61 b = 62 b = 63 b = 64 b = 65 b = 66 b = 67 b = 68 b = 69 b = 70 b = 71 b = 72 b = 73 b = 74 b = 75 b = 76 b = 77 b = 78 b = 79 b = 80 b = 81 b = 82 b = 83 b = 84 b = 85 b = 86 b = 87 b = 88 b = 89 b = 90 b = 91 b = 92 b = 93 b = 94 b = 95 b = 96 b = 97 b = 98 b = 99 b = 100 b = 101 b = 102 b = 103 b = 104 b = 105 b = 106 b = 107 b = 108 b = 109 b = 110 b = 111 b = 112 b = 113 b = 114 b = 115 b = 116 b = 117 b = 118 b = 119 b = 120 b = 121 b = 122 b = 123 b = 124 b = 125 b = 126 b = 127 b = 128 b = 129 b = 130 b = 131 b = 132 b = 133 b = 134 b = 135 b = 136 b = 137 b = 138 b = 139 b = 140 b = 141 b = 142 b = 143 b = 144 b = 145 b = 146 b = 147 b = 148 b = 149 b = 150 b = 151 b = 152 b = 153 b = 154 b = 155 b = 156 b = 157 b = 158 b = 159 b = 160 b = 161 b = 162 b = 163 b = 164 b = 165 b = 166 b = 167 b = 168 b = 169 b = 170 b = 171 b = 172 b = 173 b = 174 b = 175 b = 176 b = 177 b = 178 b = 179 b = 180 b = 181 b = 182 b = 183 b = 184 b = 185 b = 186 b = 187 b = 188 b = 189 b = 190 b = 191 b = 192 b = 193 b = 194 b = 195 b = 196 b = 197 b = 198 b = 199 b = 200 b = 201 b = 202 b = 203 b = 204 b = 205 b = 206 b = 207 b = 208 b = 209 b = 210 b = 211 b = 212 b = 213 b = 214 b = 215 b = 216 b = 217 b = 218 b = 219 b = 220 b = 221 b = 222 b = 223 b = 224 b = 225 b = 226 b = 227 b = 228 b = 229 b = 230 b = 231 b = 232 b = 233 b = 234 b = 235 b = 236 b = 237 b = 238 b = 239 b = 240 b = 241 b = 242 b = 243 b = 244 b = 245 b = 246 b = 247 b = 248 b = 249 b = 250 b = 251 b = 252 b = 253 b = 254 b = 255 b = 256 b = 257 b = 258 b = 259 b = 260 b = 261 b = 262 b = 263 b = 264 b = 265 b = 266 b = 267 b = 268 b = 269 b = 270 b = 271 b = 272 b = 273 b = 274 b = 275 b = 276 b = 277 b = 278 b = 279 b = 280 b = 281 b = 282 b = 283 b = 284 b = 285 b = 2