Cody

Problem 858. Permute diagonal and antidiagonal

Solution 263457

Submitted on 19 Jun 2013 by Dan
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 5 6;7 8 9]; y_correct = [3 2 1;4 5 6;9 8 7]; filetext = fileread('permuted.m'); assert(isequal(permuted(x),y_correct)) assert(isempty(strfind(filetext, 'diag')))

x = 3 2 1 4 5 6 7 8 9 x = 3 2 1 4 5 6 7 8 9 x = 3 2 1 4 5 6 9 8 7

2   Pass
%% x=[1 2;3 4]; y_correct = [2 1;4 3]; filetext = fileread('permuted.m'); assert(isequal(permuted(x),y_correct)) assert(isempty(strfind(filetext, 'diag')))

x = 2 1 3 4 x = 2 1 4 3

3   Pass
%% x=[1 2;3 4]; y_correct = [2 1;4 3]; filetext = fileread('permuted.m'); assert(isequal(permuted(x),y_correct)) assert(isempty(strfind(filetext, 'diag')))

x = 2 1 3 4 x = 2 1 4 3

4   Pass
%% x=magic(10); y_correct = [ 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 62 3 60 21 69 71 28 86 93 25 2 61 9 68 75 52 34 17 24 76 83 42 90 49 26 33 65 23 5 82 30 91 48 89 32 39 66 79 6 38 95 97 29 31 13 45 72 10 46 94 96 78 35 37 44 12 53 59 18 100 77 84 36 43 50 27 11]; filetext = fileread('permuted.m'); assert(isequal(permuted(x),y_correct)) assert(isempty(strfind(filetext, 'diag')))

x = 40 99 1 8 15 67 74 51 58 92 98 80 7 14 16 73 55 57 64 41 4 81 88 20 22 54 56 63 70 47 85 87 19 21 3 60 62 69 71 28 86 93 25 2 9 61 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 88 20 22 54 56 63 70 47 85 87 19 21 3 60 62 69 71 28 86 93 25 2 9 61 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 21 3 60 62 69 71 28 86 93 25 2 9 61 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 62 3 60 21 69 71 28 86 93 25 2 9 61 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 62 3 60 21 69 71 28 86 93 25 2 61 9 68 75 52 34 17 24 76 83 90 42 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 62 3 60 21 69 71 28 86 93 25 2 61 9 68 75 52 34 17 24 76 83 42 90 49 26 33 65 23 5 82 89 91 48 30 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 62 3 60 21 69 71 28 86 93 25 2 61 9 68 75 52 34 17 24 76 83 42 90 49 26 33 65 23 5 82 30 91 48 89 32 39 66 79 6 13 95 97 29 31 38 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 62 3 60 21 69 71 28 86 93 25 2 61 9 68 75 52 34 17 24 76 83 42 90 49 26 33 65 23 5 82 30 91 48 89 32 39 66 79 6 38 95 97 29 31 13 45 72 10 12 94 96 78 35 37 44 46 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 62 3 60 21 69 71 28 86 93 25 2 61 9 68 75 52 34 17 24 76 83 42 90 49 26 33 65 23 5 82 30 91 48 89 32 39 66 79 6 38 95 97 29 31 13 45 72 10 46 94 96 78 35 37 44 12 53 11 18 100 77 84 36 43 50 27 59 x = 40 99 1 8 15 67 74 51 58 92 98 64 7 14 16 73 55 57 80 41 4 81 63 20 22 54 56 88 70 47 85 87 19 62 3 60 21 69 71 28 86 93 25 2 61 9 68 75 52 34 17 24 76 83 42 90 49 26 33 65 23 5 82 30 91 48 89 32 39 66 79 6 38 95 97 29 31 13 45 72 10 46 94 96 78 35 37 44 12 53 59 18 100 77 84 36 43 50 27 11

Suggested Problems

More from this Author43

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!