构造奇数阶幻方

使用的是De la Loubère方法(也叫Siamese method)

#!/usr/bin/env python3
def magic_square(n):
    '''De la Loubere's solution for n-odd magic square'''
    square=[([0]*n) for i in range(n)]
    mid=n//2
    square[0][mid]=1
    count=1
    i=n-1 # i-th row
    j=mid+1   # j-th column
    while count

你可能感兴趣的:(构造奇数阶幻方)