Cody

# Problem 151. Magic!

Solution 2022963

Submitted on 15 Nov 2019
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   Fail
x = magic(3); y_correct = true; assert(isequal(magical(x),y_correct))

s = [] s = 8 s = 8 5 s = 8 5 2 S = 15 Z = 15 15 15 tf = logical 0

Assertion failed.

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

s = [] s = 30 s = 30 47 s = 30 47 8 s = 30 47 8 25 s = 30 47 8 25 42 s = 30 47 8 25 42 3 s = 30 47 8 25 42 3 20 S = 175 Z = 175 175 175 175 175 175 175 tf = logical 0

Assertion failed.

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

s = [] s = 1 s = 1 1 s = 1 1 1 s = 1 1 1 1 s = 1 1 1 1 1 s = 1 1 1 1 1 1 s = 1 1 1 1 1 1 1 S = 7 Z = 7 7 7 7 7 7 7 tf = logical 0

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

s = [] s = 1 s = 1 2 S = 3 Z = 3 3 tf = logical 0

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

s = [] s = 9 s = 9 6 s = 9 6 3 S = 18 Z = 18 18 18 tf = logical 0

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

s = [] s = 37 s = 37 38 s = 37 38 39 s = 37 38 39 40 s = 37 38 39 40 41 s = 37 38 39 40 41 42 s = 37 38 39 40 41 42 43 s = 37 38 39 40 41 42 43 44 s = 37 38 39 40 41 42 43 44 45 S = 369 Z = 369 369 369 369 369 369 369 369 369 tf = logical 0

Assertion failed.

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

s = [] s = 66 s = 66 65 s = 66 65 64 s = 66 65 64 63 s = 66 65 64 63 62 s = 66 65 64 63 62 61 s = 66 65 64 63 62 61 60 s = 66 65 64 63 62 61 60 59 s = 66 65 64 63 62 61 60 59 58 s = 66 65 64 63 62 61 60 59 58 57 s = 66 65 64 63 62 61 60 59 58 57 56 S = 671 Z = 671 671 671 671 671 671 671 671 671 671 671 tf = logical 0

Assertion failed.

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

s = [] s = 16 s = 16 11 s = 16 11 6 s = 16 11 6 1 S = 34 Z = 34 34 34 34 tf = logical 0

Assertion failed.

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

s = [] s = 8 s = 8 15 s = 8 15 22 s = 8 15 22 29 s = 8 15 22 29 36 s = 8 15 22 29 36 43 s = 8 15 22 29 36 43 50 s = 8 15 22 29 36 43 50 57 S = 260 Z = 260 260 260 260 260 260 260 260 tf = logical 0

Assertion failed.

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

s = [] s = 1 s = 1 4 S = 5 Z = 5 5 tf = logical 0

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

s = [] s = 1 s = 1 5

Index in position 1 exceeds array bounds (must not exceed 2). Error in magical (line 4) s(end+1)=x(i,i) Error in Test11 (line 3) assert(isequal(magical(x),y_correct))

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

s = [] s = 1 s = 1 1 S = 2 Z = 2 2 tf = logical 0

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

s = [] s = 7 s = 7 5 s = 7 5 3 S = 15 Z = 15 15 15 tf = logical 0