2017-08-16 22:54:45 +08:00

61 lines
1.1 KiB
Python

def two(a, b):
out = set([])
out.add(a + b)
out.add(a * b)
'''if a != b:
out.add(abs(a - b))'''
out.add(a - b)
out.add(b - a)
if a != 0:
out.add(b / float(a))
if b != 0:
out.add(a / float(b))
return out
def three(a, b, c):
out = set([])
for i in two(a, b):
out |= two(i, c)
for i in two(a, c):
out |= two(i, b)
for i in two(b, c):
out |= two(i, a)
return out
def four(a, b, c, d):
first = two(a, b)
second = two(c, d)
out = set([])
for i in first:
out |= three(i, c, d)
for j in second:
out |= two(i, j)
for j in second:
out |= three(j, a, b)
return out
def calc(a, b, c, d):
tmp = set([])
tmp |= four(a, b, c, d)
tmp |= four(a, c, b, d)
tmp |= four(a, d, b, c)
out = []
for i in tmp:
if i == int(i) > 0:
out.append(int(i))
return sorted(out)
maxx = [0, 0]
for m in xrange(1, 10):
for n in xrange(m + 1, 10):
for s in xrange(n + 1, 10):
for t in xrange(s + 1, 10):
tmp = calc(m, n, s, t)
for i in xrange(len(tmp)):
if i + 1 != tmp[i]:
break
if i > maxx[0]:
maxx = [i, (m, n, s, t)]
print maxx