posted 10 years ago
Magic square - n × n(4 x 4 in this case) matrix that is filled with the numbers 1, 2, 3, . . ., n2

Conditions: 1.Are the numbers 1, 2, ..., 16 the input.

2. And is the sums of the rows, columns, and diagonals equal to each other?

Question/request for assistance one: i wonder if there is a more optimal way of comparing elements of two arrays. I predefined an array at line 67 expectedArr, and then removed elements from that array that fall into the right-input category. So basically i am wondering how can checking if one array contains all the elements of another arrays be done better, an easier way?

And at line 120. i first ran with return equalSumRowsColumns (arr, a++) && sumOfRow(arr[a]) == sumOfColumn(arr, a); which lead to the following error -> java.lang.StackOverflowError. But when i replaced it with a + 1 there is no error. I thought that maybe a++ 'instantly' changes the value of a so on next uses it is already updated when it shouldn't be, so i changed it to a + 1, but isnt a++ same as a + 1, confused...

Edit1: example of a magic square