A Magic Square contains the integers 1 to n^(2), arranged in an n by n array such that the columns, rows and both main diagonals add up to the same number.For doubly even positive integers (multiples of 4) the following method can be used to create a magic square.
Fill an array with the numbers 1 to n^(2) in succession. Then, for each 4 by 4 subarray, replace the entries on the blue and red diagonals by n^(2)+1-aij.
So, in the following example, a11 (row 1, column 1) was initially 1 and is replaced by 8^(2)+1-1 = 64
    tab1 { padding-left: 2em; }
    fc1  { font color="blue"}
n=8
642 3 61606 7 57 
9 55541213515016
1747462021434224
4026273736303133
3234352928383925
4123224445191848
4915145253111056
8 58595 4 62631 
The function even_magic() should return a 2D array as follows:-
Example:
n=4: Output: [[16,2,3,13],[5,11,10,8],[9,7,6,12],[4,14,15,1]]
162 3 13
5 11108 
9 7 6 12
4 14151 
Only doubly even numbers will be passed to the function in the tests.
See mathworld.wolfram.com for further details.
def even_magic(n):
    sq = [[y*n+x+1 for x in range(n)] for y in range(n)]
    
    for x in range(n):
        for y in range(n):
            if y % 4 == x % 4 or y % 4 == 3-x % 4:
                sq[x][y] = n**2 + 1 - sq[x][y]
    return sq

def even_magic(n):
    sq = [[y*n+x+1 for x in range(n)] for y in range(n)]
    
    for x in range(n):
        for y in range(n):
            if y % 4 == x % 4 or y % 4 == 3-x % 4:
                sq[x][y] = n**2 + 1 - sq[x][y]
    return sq
