Problem 314. Find the sum of the elements in the "second" diagonal
Solution Stats
Problem Comments
-
4 Comments
you might want to make a case that's not a magic square, considering the properties of the diagonals of a magic square...
There are only magic squares in test cases, however the problem doesn't specify a type of the matrix.
You should definitely strengthen the test suite. Lots of solutions rely on both diagonals being the same, even though this is not a property of the stated problem.
The "antidiagonal" is cooler sounding than "second diagonal"
Solution Comments
-
2 Comments
I learned about fliplr() in another problem and it is helpful here!
Thanks for the hint
-
1 Comment
I like you're use of a nested loop here.
-
3 Comments
The last test suite result should be 14.
yes ı agree
Trickey ONE indeed !!
-
1 Comment
But you can't rely on x always being a magic square - that's just an accident of the inadequate test suite, isn't it? So although this *looks* like a good solution, it isn't really. I think it's bad practice to take advantage of an inadequate test suite.
-
1 Comment
it doesn't find the sum of the elements of the second but first diagonal
Problem Recent Solvers1088
Suggested Problems
-
Determine whether a vector is monotonically increasing
16663 Solvers
-
Back to basics 17 - white space
266 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
339 Solvers
-
Right Triangle Side Lengths (Inspired by Project Euler Problem 39)
1305 Solvers
-
506 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!