本帖最后由 substr函数 于 2015-07-05 20:40 编辑
作为一个轻量级的存在
我也这么写了
- a, b, c, d, e, f, g, h, i = (9, 5, 4, 6, 3, 2, 1, 7, 8)
- a, b, c, d, e, f, g, h, i = (9, 5, 4, 6, 3, 2, 7, 1, 8)
复制代码- #!/usr/bin/python2
- # coding: utf-8
- from itertools import permutations as P
- def check1(c, d, e, i):
- return d * c == e * i
- def check2(a, b, c, g, h, i):
- return a - b == c and g + h == i
- nine = set(range(1, 10))
- VARS = 'a, b, c, d, e, f, g, h, i = '
- for four in P(range(1, 10), 4):
- if check1(*four):
- F, m = divmod(four[-1], four[0])
- if m: continue
- c, d, e, i = four
- for five in P(nine - set(four)):
- if five[2] != F: continue
- a, b, f, g, h = five
- if check2(a, b, c, g, h, i):
- print VARS, (a, b, c, d, e, f, g, h, i)
-
复制代码 |