This could be improved with a better test suite. For example, flipud(magic(n)) is still magical, but most of the leading solutions would return false for this.
Yes, test suite is substandard. Could have drawn from this: http://nrich.maths.org/1338
Why is magic(2) not a magic square ?
I was not notified about some of the older comments, so was unaware of some of the weaknesses of the test suite, and the "gamed" solutions. I have substantially improved the test suite.
The MATLAB command magic(2), although it does produce output, is not a magic square, according to the definition. (There is no 2x2 magic square.)
x = magic(2);
y_correct = false;
This is wrong!!!! hence solution failed
Although MATLAB does create a 2x2 matrix as an output from magic(2), that output is not a magic square.
I'm pretty sure test 5 is wrong. magic(3)+1: sum of every row, column, and both diagonals is 18
It's not a normal magic square if it's of size 3x3 and doesn't sum to 15. All rows/cols/diags must sum to n*(n^2+1)/2.
I don't think this checks the diagonals. Is that because it's not necessary?
issame is from which toolbox ?
passed in matlab but not here??what ??
Test 4 is wrong: y_correct should be = TRUE
No, test 4 is correct. magic(2) does not return a magic square.
Hein? -348052801600 where does this number come from?!
Note that this gives the wrong result for magic(4). I suspect that this is tailored to the test set.
I like this since there is nothing in the MATLAB doc which guarantees that magic() produces a normal magic square. Is it necessary to also check both diagonals?
Folks, I don't get it. If you create z= magic(3)', that's a magic square. No surprise. If you then do an isequal with magic(3), you fail the test. Thus this and all solutions of this class are wrong, marked as correct only because the tests don't offer transposed magic squares as a test. The test vector needs to be fixed so all these solutions show us as not working.
Sorted highest to lowest?
give nth decimal place of pi
Test if a Number is a Palindrome without using any String Operations
Find the logic
Right and wrong
Tune your guitar
Are you in or are you out?
Figurate number triangle
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office