mathematica解决填符号使等式成立问题在网上曾经看到过一个高手用列举法解决一个(34口5口6口8口9口1)口2=2008在口中填入加减乘使等式成立程序如下,但是如果题目要求填入加减乘除和括号,程序要怎么改进啊比如(5+5+5)÷5+5=8,即5 5 5 5 5=8填入相应符号info = expr[{"+"},{"-"},{"*"}]; For [a = 1,a For [b = 1,b For [c = 1,c For [d = 1,d For [e = 1,e For [f = 1,f temp = StringJoin["(34",Part[info,a],"5",Part[info,b],"6",Part[info,c],"8",Part[info,d],"9",Part[info,e],"1)",Part[info,f],"2"]; If [ToExpression[temp] == 2008,Print[temp]] ]]]]]]

问题描述:

mathematica解决填符号使等式成立问题
在网上曾经看到过一个高手用列举法解决一个
(34口5口6口8口9口1)口2=2008
在口中填入加减乘使等式成立
程序如下,但是如果题目要求填入加减乘除和括号,程序要怎么改进啊
比如(5+5+5)÷5+5=8,即5 5 5 5 5=8填入相应符号
info = expr[{"+"},{"-"},{"*"}];
For [a = 1,a For [b = 1,b For [c = 1,c For [d = 1,d For [e = 1,e For [f = 1,f temp =
StringJoin["(34",Part[info,a],"5",Part[info,b],"6",
Part[info,c],"8",Part[info,d],"9",Part[info,e],"1)",
Part
[info,f],"2"]; If [ToExpression[temp] == 2008,Print[temp]]
]]]]]]