Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import permutations
- import operator
- def solve(n1, n2, n3, solution):
- operations = {
- operator.mul: "x",
- operator.truediv: "/",
- operator.sub: "-",
- operator.add: "+",
- operator.mod: "%",
- operator.pow: "^"
- }
- solutions = []
- for (a, b, c) in permutations([n1, n2, n3]):
- for op1 in operations:
- for op2 in operations:
- if op1(op2(a, b), c) == solution:
- solutions.append("{} {} {} {} {} = {}".format(
- a,
- operations[op2],
- b,
- operations[op1],
- c,
- solution
- ))
- return solutions
- solve(10, 5, 7, 14)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement