def two(a, b): out = set([a + b, a * b, a - b, b - a]) if a != 0: out.add(b / a) if b != 0: out.add(a / 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): pair = two(c, d) out = set([]) for i in two(a, b): out |= three(i, c, d) for j in pair: out |= two(i, j) for j in pair: out |= three(j, a, b) return out def calc(a, b, c, d): out = list(sorted(list(filter(lambda x: x == int(x) > 0, four(a, b, c, d) | four(a, c, b, d) | four(a, d, b, c))))) for i in range(len(out)): if i + 1 != out[i]: return out[:i] return out def search(): maxi = [0, 0] for m in range(1, 10): for n in range(m + 1, 10): for s in range(n + 1, 10): for t in range(s + 1, 10): count = len(calc(m, n, s, t)) if count > maxi[0]: maxi = [count, (m, n, s, t)] return maxi print(search())