Skip to content

24 #2

@emptymalei

Description

@emptymalei
著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者:丁小文
链接:http://zhuanlan.zhihu.com/dingwen/20523241
来源:知乎

toExprs[t_List] := Block[{x = ToString@t[[1]], y = ToString@t[[2]]},
   Prepend[t[[-Length@t + 2 ;;]], #] & /@ ("(" <> # <> ")" & /@ 
      Flatten[{x <> # <> y, y <> # <> x} & /@ {"+", "-", "*", "/"}])];
f[s_] := Flatten[toExprs[#] & /@ s, 1];
solve[num_List] := Block[{nums = Permutations[num]},
   Select[
    StringTake[
     DeleteDuplicates@
      Flatten@Nest[f, nums, Length[num] - 1], {2, -2}], 
    Quiet@ToExpression[#] == 25 &]];

solve[{1, 2, 3, 4}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions