Cody

Problem 151. Magic!

Solution 2022945

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 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 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 tf = logical 0

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

s = [] s = 1 s = 1 2

Output argument "tf" (and maybe others) not assigned during call to "magical". Error in Test4 (line 3) assert(isequal(magical(x),y_correct))

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 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 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 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 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 tf = logical 0

Assertion failed.

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

s = [] s = 1 s = 1 4

Output argument "tf" (and maybe others) not assigned during call to "magical". Error in Test10 (line 3) assert(isequal(magical(x),y_correct))

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 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 tf = logical 0

Suggested Problems

More from this Author23