请问各位大神怎么化简此代码
怎么化简这个代码,不然不符合python洁简的风格{:5_109:}for a in range(1,10):
for b in range(1,10):
for c in range(1,10):
for d in range(1,10):
for e in range(1,10):
for f in range(1,10):
for g in range(1,10):
for h in range(1,10):
for i in range(1,10):
if (a + b + c) == 15 and (a + d + g ) == 15 and (a + e + i ) == 15 and (d + e + f)==15 and (g + h + i )==15:
if a != b and a != c and a != d and a != e and a != f and a != g and a != h and a != i:
if b != c and b !=d and b != e and b != f and b != g and b != h and b != i :
if c != d and c != e and c != f and c != g and c != h and c != i :
if d !=e and d != fand d != gand d !=h and d != i :
if e != f ande != g ande != h ande != i :
if f !=g and f != handf != i :
if g != hand g != i:
if h !=i :
print(a,b,c,d,e,f,g,h,i)
说说这代码是干嘛的
有点儿费眼 昨非 发表于 2020-12-19 11:43
说说这代码是干嘛的
有点儿费眼
就是九宫格,横竖斜都等于15,
各个字母对应的位置分别是:
---------------------
a b c
d e f
g h i
---------------------- 本帖最后由 逃兵 于 2020-12-19 15:44 编辑
九宫格就满足几点
1.中点e=5
2.四个角为偶数acgi为偶数
又因为中点e必定为5
则有i=10-a,g=10-c
3.定一个角a时,只有两种写法(分别互换cg的值,对应影响到bdfh的值)
a一定为偶数,所以一共有2*4=8种解
angle = [,]
e = 5
for num in range(len(angle)):
for a in angle:
i = 10-a
for c in angle:
g = 10-c
b = 15-a-c
h = 10-b
d = 15-a-g
f = 10-d
print(a,b,c,d,e,f,g,h,i) 逃兵 发表于 2020-12-19 14:47
九宫格就满足几点
1.中点e=5
2.四个角为偶数acgi为偶数
谢谢大佬
页:
[1]