Cody

Problem 151. Magic!

Solution 547952

Submitted on 19 Dec 2014 by Kevin
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))

t1 = 15 t2 = 15 i = 2 t1 = 15 t2 = 15 i = 3 t1 = 15 t2 = 15 i = 4 tf = 1

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

t1 = 175 t2 = 175 i = 2 t1 = 175 t2 = 175 i = 3 t1 = 175 t2 = 175 i = 4 t1 = 175 t2 = 175 i = 5 t1 = 175 t2 = 175 i = 6 t1 = 175 t2 = 175 i = 7 t1 = 175 t2 = 175 i = 8 tf = 1

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

t1 = 1 t2 = 1

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

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

t1 = 18 t2 = 18

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

t1 = 369 t2 = 369 i = 2 t1 = 369 t2 = 369 i = 3 t1 = 369 t2 = 369 i = 4 t1 = 369 t2 = 369 i = 5 t1 = 369 t2 = 369 i = 6 t1 = 369 t2 = 369 i = 7 t1 = 369 t2 = 369 i = 8 t1 = 369 t2 = 369 i = 9 t1 = 369 t2 = 369 i = 10 tf = 1

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

t1 = 671 t2 = 671 i = 2 t1 = 671 t2 = 671 i = 3 t1 = 671 t2 = 671 i = 4 t1 = 671 t2 = 671 i = 5 t1 = 671 t2 = 671 i = 6 t1 = 671 t2 = 671 i = 7 t1 = 671 t2 = 671 i = 8 t1 = 671 t2 = 671 i = 9 t1 = 671 t2 = 671 i = 10 t1 = 671 t2 = 671 i = 11 t1 = 671 t2 = 671 i = 12 tf = 1

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

t1 = 34 t2 = 34 i = 2 t1 = 34 t2 = 34 i = 3 t1 = 34 t2 = 34 i = 4 t1 = 34 t2 = 34 i = 5 tf = 1

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

t1 = 260 t2 = 260 i = 2 t1 = 260 t2 = 260 i = 3 t1 = 260 t2 = 260 i = 4 t1 = 260 t2 = 260 i = 5 t1 = 260 t2 = 260 i = 6 t1 = 260 t2 = 260 i = 7 t1 = 260 t2 = 260 i = 8 t1 = 260 t2 = 260 i = 9 tf = 1

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

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

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

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

t1 = 14 t2 = 14

Suggested Problems

More from this Author23

Community Treasure Hunt

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

Start Hunting!