What do you exactly mean?
the first part with M? this is definitly wrong. just try n = 4.
in their set phrase the Sum should be 43. but it isnt. a magic square of n=4 has a sum of 34(!!). the real set phrase has to be :
M = n/2 * (n+1)
-> n means cells (=16)
M = 16/2 * 17
M = 8 * 17
M = 136
136 : 4 = 34
if you meant the constructing part, then: this doesnt work neither. because i have initial values, so i cant work with a system. i have to "backtrack"
My hole programm runs correctly. if n=3, then it take me just 250ms to generate the square. but with n=4 i need 3h(!!).
Oh gosh, your code is rather confusing... I think it's because I'm not sure what your methods and variable are meant to do. If the algo is taking that long to compute the answer (does it give the correct answer?) then it is flawed.
My first question: the method isMagisch, what does that check? Based on the name, I'd assume it determines if the matrix is 'magic' or not?
My second question: How do you verify that the numbers you generate are not duplicated?
isMagisch checks the entire square (collums,rows and diagonales).
to verify i wrote a method checkNum(), which goes threw the array and checks wether the number is used or not. then it returns true or false
if its true (== number is already justed) then he adds 1.
My suggestion: Sum the diagonal that goes from left to right in which case the indices increment by 1 for both dimensions of the matrix, that is, [i][i] where i is the counter in the for loop.
Then sum the other diagonal, where one dimension increases as the other decreases (the pairs would be {0, 2}; {1, 1}; {2, 0}). If the sum of the previous diagonal is the same as the newly calculated sum then proceed.
okay, you mean, that i have to check only the diagonales, while i am filling it?!
what should it be good for? it doesnt proof anything
Oh, one last comment: it seems that you're using n to store the dimension of your matric. Rather use quadrat.length or quadrat[0].length where both length final variables would have the same value. Let me know if you don't understand this concept.
stupid question, but why? where is the difference? i tought it would be easier for the "user"
thanks for your patience