Remarks about the magic order-6 program

 Why are the numbers of the cells not described in an array? The variables i11, i21, ... work much faster than a two-dimensional array. Why are integers from -1 to 34 used? The lowest integer shall be placed first. With -1 as lowest integer we have left 0, 1, ..., 34. When a random integer is choosen with Rand(35) the lowest possible result is 0. And that is exactly what we want. The two cases A and B In the case A the lowest number (-1) is placed in the cell (1,1): i11 = -1 Additionally: i21 < i31, i41, i51 and i31 < i41 and i61 < i16 All magic squares of order 6 with the lowest number in any main-diagonal can be transformed so that they meet these conditions. Each single magic square generates 24 different magic squares. The number of squares we find in this case has to be multiplied by 24 (= TrfRed). In the case B the lowest number (-1) is placed in the cell (2,1): i21 = -1 Additionally: i11 < i61 and i31 < i41 and i51 < i26 The number of squares we find in this case also has to be multiplied by 24. Very important: the byte array st() If st(x)=1 then the integer x is not yet placed in any cell. If st(x)=0 then the integer x is already placed in a cell or the integer is too small or too large. So we only have to check st(x) when we want to place the integer x, we do not have to check whether x is within the considered number range. At the beginning st(x) is set to 1 for all suitable integers x and 0 for all others. The type of st() may also be boolean, but the addressing seems to be slightly faster with the type byte. The Monte Carlo lines Say it is the turn of cell (x,y) to be filled with an integer and say m integers were already in use. Normaly we would have to try all left (36 - m) integers within a for-loop. But this would take too much time, therefore we choose one of the free integers by chance. Statistically we then will find less magic squares according to a factor of 1/(36 - m). If the Monte Carlo code is used for the first cells we get large variances leading to inaccurate mean values. If we use it for the last filled cells the calculation time only decreases very little. It is best to apply the code to cells that were filled in the middle.