马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 半灵桑 于 2023-11-19 17:36 编辑
我最近闲着没事,整了个十阶幻方生成器:
#made with python3.10
import random
print('生成中……\n')
while True:
x = []
for count in range(10):
x.append([])
for count in range(10):
x[0].append(random.randint(-9999999999, 1000000000))
x[1].append(random.randint(-9999999999, 1000000000))
x[2].append(random.randint(-9999999999, 1000000000))
x[3].append(random.randint(-9999999999, 1000000000))
x[4].append(random.randint(-9999999999, 1000000000))
x[5].append(random.randint(-9999999999, 1000000000))
x[6].append(random.randint(-9999999999, 1000000000))
x[7].append(random.randint(-9999999999, 1000000000))
x[8].append(random.randint(-9999999999, 1000000000))
x[9].append(random.randint(-9999999999, 1000000000))
a = bool(sum(x[0]) == sum(x[1]) == sum(x[2])== sum(x[3]) == sum(x[4]) \
== sum(x[5]) == sum(x[6]) == sum(x[7])== sum(x[8]) == sum(x[9]))
b = bool(x[0][0] + x[0][1] + x[0][2] + x[0][3] + x[0][4] + x[0][5] + x[0][6] + x[0][7] + x[0][8] + x[0][9] == \
x[1][0] + x[1][1] + x[1][2] + x[1][3] + x[1][4] + x[1][5] + x[1][6] + x[1][7] + x[1][8] + x[1][9] == \
x[2][0] + x[2][1] + x[2][2] + x[2][3] + x[2][4] + x[2][5] + x[2][6] + x[2][7] + x[2][8] + x[2][9] == \
x[3][0] + x[3][1] + x[3][2] + x[3][3] + x[3][4] + x[3][5] + x[3][6] + x[3][7] + x[3][8] + x[3][9] == \
x[4][0] + x[4][1] + x[4][2] + x[4][3] + x[4][4] + x[4][5] + x[4][6] + x[4][7] + x[4][8] + x[4][9] == \
x[5][0] + x[5][1] + x[5][2] + x[5][3] + x[5][4] + x[5][5] + x[5][6] + x[5][7] + x[5][8] + x[5][9] == \
x[6][0] + x[6][1] + x[6][2] + x[6][3] + x[6][4] + x[6][5] + x[6][6] + x[6][7] + x[6][8] + x[6][9] == \
x[7][0] + x[7][1] + x[7][2] + x[7][3] + x[7][4] + x[7][5] + x[7][6] + x[7][7] + x[7][8] + x[7][9] == \
x[8][0] + x[8][1] + x[8][2] + x[8][3] + x[8][4] + x[8][5] + x[8][6] + x[8][7] + x[8][8] + x[8][9] == \
x[9][0] + x[9][1] + x[9][2] + x[9][3] + x[9][4] + x[9][5] + x[9][6] + x[9][7] + x[9][8] + x[9][9] )
c = bool(x[0][0] + x[1][1] + x[2][2] + x[3][3] + x[4][4] + x[5][5] + x[6][6] + x[7][7] + x[8][8] + x[9][9] == \
x[0][9] + x[1][8] + x[2][7] + x[3][6] + x[4][5] + x[5][4] + x[6][3] + x[7][2] + x[8][1] + x[9][0])
d = bool(x[0][0] != x[0][1] != x[0][2] != x[0][3] != x[0][4] != x[0][5] != x[0][6] != x[0][7] != x[0][8] != \
x[0][9] != x[1][0] != x[1][1] != x[1][2] != x[1][3] != x[1][4] != x[1][5] != x[1][6] != x[1][7] != \
x[1][8] != x[1][9] != x[2][0] != x[2][1] != x[2][2] != x[2][3] != x[2][4] != x[2][5] != x[2][6] != \
x[2][7] != x[2][8] != x[2][9] != x[3][0] != x[3][1] != x[3][2] != x[3][3] != x[3][4] != x[3][5] != \
x[3][6] != x[3][7] != x[3][8] != x[3][9] != x[4][0] != x[4][1] != x[4][2] != x[4][3] != x[4][4] != \
x[4][5] != x[4][6] != x[4][7] != x[4][8] != x[4][9] != x[5][0] != x[5][1] != x[5][2] != x[5][3] != \
x[5][4] != x[5][5] != x[5][6] != x[5][7] != x[5][8] != x[5][9] != x[6][0] != x[6][1] != x[6][2] != \
x[6][3] != x[6][4] != x[6][5] != x[6][6] != x[6][7] != x[6][8] != x[6][9] != x[7][0] != x[7][1] != \
x[7][2] != x[7][3] != x[7][4] != x[7][5] != x[7][6] != x[7][7] != x[7][8] != x[7][9] != x[8][0] != \
x[8][1] != x[8][2] != x[8][3] != x[8][4] != x[8][5] != x[8][6] != x[8][7] != x[8][8] != x[8][9] != \
x[9][0] != x[9][1] != x[9][2] != x[9][3] != x[9][4] != x[9][5] != x[9][6] != x[9][7] != x[9][8] != x[9][9])
if a == b == c == d == True :
break
print('生成完毕!\n')
print(*x[0])
print(*x[1])
print(*x[2])
print(*x[3])
print(*x[4])
print(*x[5])
print(*x[6])
print(*x[7])
print(*x[8])
print(*x[9])
跑不动,根本跑不动啊(
明明没有错误嘛( |