E
E
Elnur Tazhimbetov2017-09-20 19:47:58
Python
Elnur Tazhimbetov, 2017-09-20 19:47:58

Given three numbers A, B, C, you need to mix the numbers inside A B C so that the sum of A and B gives C, how to do this?

For example, the number 54 12 75 will come in, and should output 54+21=75

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2017-09-20
@tazhimbetov

from itertools import permutations, product

def acronyms(x):
    res = {x}
    for digs in permutations(str(x)):
        if digs[0] != '0': # число, если не ноль, не начинается с нуля
            res.add(int(''.join(digs)))
    return res

a, b, c = 54, 12, 75
zz = acronyms(c)
for x, y in product(acronyms(a), acronyms(b)):
    if x + y in zz:
        print("%d + %d = %d" % (x, y, x + y))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question