Skip to main content
added 18 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
stripParentheses = Function[, StringReplace["(" | ")" | " " -> ""] @
    ToString[Unevaluated @ #, InputForm], HoldFirst];

stripParentheses[3*2 + 2/4*10]

enter image description here

ops = {"/", "*", "+"};

split = StringSplit[stripParentheses[3*2 + 2/4*10], a : Alternatives @@ ops :> a]

enter image description here

parenthesize = SequenceReplace[#, {a_, #2, b_} :> StringJoin["(",a,#2,b,")"]]&;


Map[{#, ## & @@ {StringJoin @ #, ToExpression @ StringJoin @ #} & @
   Fold[parenthesize, split, #]} &&] /@ Permutations[ops] // 
 Grid[#, Dividers -> All] &

enter image description hereenter image description here

stripParentheses = Function[, StringReplace["(" | ")" | " " -> ""] @
    ToString[Unevaluated @ #, InputForm], HoldFirst];

stripParentheses[3*2 + 2/4*10]

enter image description here

ops = {"/", "*", "+"};

split = StringSplit[stripParentheses[3*2 + 2/4*10], a : Alternatives @@ ops :> a]

enter image description here

parenthesize = SequenceReplace[#, {a_, #2, b_} :> StringJoin["(",a,#2,b,")"]]&;


{StringJoin @ #, ToExpression @ StringJoin @ #} & @
  Fold[parenthesize, split, #] & /@ Permutations[ops] // 
 Grid[#, Dividers -> All] &

enter image description here

stripParentheses = Function[, StringReplace["(" | ")" | " " -> ""] @
    ToString[Unevaluated @ #, InputForm], HoldFirst];

stripParentheses[3*2 + 2/4*10]

enter image description here

ops = {"/", "*", "+"};

split = StringSplit[stripParentheses[3*2 + 2/4*10], a : Alternatives @@ ops :> a]

enter image description here

parenthesize = SequenceReplace[#, {a_, #2, b_} :> StringJoin["(",a,#2,b,")"]]&;


Map[{#, ## & @@ {StringJoin @ #, ToExpression @ StringJoin @ #} & @
   Fold[parenthesize, split, #]} &] @ Permutations[ops] // 
 Grid[#, Dividers -> All] &

enter image description here

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

stripParentheses = Function[, StringReplace["(" | ")" | " " -> ""] @
    ToString[Unevaluated @ #, InputForm], HoldFirst];

stripParentheses[3*2 + 2/4*10]

enter image description here

ops = {"/", "*", "+"};

split = StringSplit[stripParentheses[3*2 + 2/4*10], a : Alternatives @@ ops :> a]

enter image description here

parenthesize = SequenceReplace[#, {a_, #2, b_} :> StringJoin["(",a,#2,b,")"]]&;


{StringJoin @ #, ToExpression @ StringJoin @ #} & @
  Fold[parenthesize, split, #] & /@ Permutations[ops] // 
 Grid[#, Dividers -> All] &

enter image description here