Operators Game that really confusing

28 Views Asked by At

I saw this question on the newspaper and can't solve it, help. Use the four operation sign, substitute them into the question marks between the digits such that the outcome is two(the order of operation doesn't applied, each operation is done one at a time) -7?6?22?2?-5?14?9=2

1

There are 1 best solutions below

1
On

My computer program found two solutions: $$ (((((-7+6)*22)+2)/-5)+14)/9 = 2 \\ (((((-7-6)+22)/2)+-5)*14)+9 = 2 $$

Here is my sage program: def combs(S,k): if k == 0: yield [] else: for x in S: for y in combs(S,k-1): yield [x] + y def op(x): if x == '+': return lambda y,z:y+z if x == '-': return lambda y,z:y-z if x == '*': return lambda y,z:y*z if x == '/': return lambda y,z:y/z def app(O): res = -7 for (oper,operand) in zip(O,[6,22,2,-5,14,9]): res = op(oper)(res,operand) return res [comb for comb in combs('+-*/',6) if app(comb)==2]

The output is [['+', '*', '+', '/', '+', '/'], ['-', '+', '/', '+', '*', '+']].