Cody

Problem 44450. Create a magic square matrix for a given odd integer

Solution 3438363

Submitted on 27 Oct 2020
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
n = 3; y_correct = [15 15 15 15]; %row sum, col sum, main diag sum, other diag sum [a b c d] = MagicSquare(n); assert(isequal([a b c d],y_correct))

Error using .* Too many output arguments. Error in MagicSquare (line 4) [row1Sum, col1Sum, diag1Sum, adiagSum] =k(1,1).*[1 1 1 1] Error in Test1 (line 3) [a b c d] = MagicSquare(n);

2   Fail
n = 5; y_correct = [65 65 65 65]; %row sum, col sum, main diag sum, other diag sum [a b c d] = MagicSquare(n); assert(isequal([a b c d],y_correct))

Error using .* Too many output arguments. Error in MagicSquare (line 4) [row1Sum, col1Sum, diag1Sum, adiagSum] =k(1,1).*[1 1 1 1] Error in Test2 (line 3) [a b c d] = MagicSquare(n);

3   Fail
n = 9; y_correct = [369 369 369 369]; %row sum, col sum, main diag sum, other diag sum [a b c d] = MagicSquare(n); assert(isequal([a b c d],y_correct))

Error using .* Too many output arguments. Error in MagicSquare (line 4) [row1Sum, col1Sum, diag1Sum, adiagSum] =k(1,1).*[1 1 1 1] Error in Test3 (line 3) [a b c d] = MagicSquare(n);

4   Fail
n = 15; y_correct = [1695 1695 1695 1695]; %row sum, col sum, main diag sum, other diag sum [a b c d] = MagicSquare(n); assert(isequal([a b c d],y_correct))

Error using .* Too many output arguments. Error in MagicSquare (line 4) [row1Sum, col1Sum, diag1Sum, adiagSum] =k(1,1).*[1 1 1 1] Error in Test4 (line 3) [a b c d] = MagicSquare(n);

Community Treasure Hunt

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

Start Hunting!