Cody

Problem 151. Magic!

Solution 460206

Submitted on 22 Jun 2014 by Abdullah Caliskan
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 = magic(3); y_correct = true; assert(isequal(magical(x),y_correct))

a1 = 8 1 6 3 5 7 4 9 2 ans = 1

2   Pass
%% x = magic(7); y_correct = true; assert(isequal(magical(x),y_correct))

a1 = 30 39 48 1 10 19 28 38 47 7 9 18 27 29 46 6 8 17 26 35 37 5 14 16 25 34 36 45 13 15 24 33 42 44 4 21 23 32 41 43 3 12 22 31 40 49 2 11 20 ans = 1

3   Pass
%% x = eye(7); y_correct = false; assert(isequal(magical(x),y_correct))

a1 = 30 39 48 1 10 19 28 38 47 7 9 18 27 29 46 6 8 17 26 35 37 5 14 16 25 34 36 45 13 15 24 33 42 44 4 21 23 32 41 43 3 12 22 31 40 49 2 11 20 ans = 0

4   Pass
%% x = magic(2); y_correct = false; assert(isequal(magical(x),y_correct))

a1 = 1 3 4 2 ans = 0

5   Pass
%% x = magic(3)+1; y_correct = false; assert(isequal(magical(x),y_correct))

a1 = 8 1 6 3 5 7 4 9 2 ans = 0

6   Pass
%% x = flipud(magic(9)); y_correct = true; assert(isequal(magical(x),y_correct))

a1 = 47 58 69 80 1 12 23 34 45 57 68 79 9 11 22 33 44 46 67 78 8 10 21 32 43 54 56 77 7 18 20 31 42 53 55 66 6 17 19 30 41 52 63 65 76 16 27 29 40 51 62 64 75 5 26 28 39 50 61 72 74 4 15 36 38 49 60 71 73 3 14 25 37 48 59 70 81 2 13 24 35 ans = 1

7   Pass
%% x = fliplr(magic(11)); y_correct = true; assert(isequal(magical(x),y_correct))

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

8   Pass
%% x = magic(4); y_correct = true; assert(isequal(magical(x),y_correct))

a1 = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 ans = 1

9   Pass
%% x = flipud(magic(8)); y_correct = true; assert(isequal(magical(x),y_correct))

a1 = 64 2 3 61 60 6 7 57 9 55 54 12 13 51 50 16 17 47 46 20 21 43 42 24 40 26 27 37 36 30 31 33 32 34 35 29 28 38 39 25 41 23 22 44 45 19 18 48 49 15 14 52 53 11 10 56 8 58 59 5 4 62 63 1 ans = 1

10   Pass
%% x = [1 2; 3 4]; y_correct = false; assert(isequal(magical(x),y_correct))

a1 = 1 3 4 2 ans = 0

11   Pass
%% x = [1 2 3; 4 5 6]; y_correct = false; assert(isequal(magical(x),y_correct))

a1 = 1 3 4 2 ans = 0

12   Pass
%% x = ones(2); y_correct = false; assert(isequal(magical(x),y_correct))

a1 = 1 3 4 2 ans = 0

13   Pass
%% x = [7 1 6; 3 5 7; 4 9 3]; y_correct = false; assert(isequal(magical(x),y_correct))

a1 = 8 1 6 3 5 7 4 9 2 ans = 0

Community Treasure Hunt

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

Start Hunting!