### Hyper@2016-03-16

Class=Mathematica Calculating24

Calculating24

ops = Map[Inactive,

Tuples[{Times, Plus, Subtract, Divide}, {4 - 1}], {2}];

rules = Thread[{a, b, c} -> #] & /@ ops;

matchQ[list_] :=

Module[{},

res = Fold[Replace[#1, List -> #2[], {#2[]}, Heads -> True] &,

list, Transpose@{{a, b, c}, {1, 2, 3}}] /. rules //.

Inactive[Subtract][x_, y_] :> Inactive[Plus][x, -y];

Select[res, Activate[#] == 24 &]]

list = {6, 4, 2, 3};

pattern = {{#[[1 ;; 2]], #[[3 ;; 4]]}, {#[[

1]], {#[], #[[3 ;; 4]]}},

Reverse@{#[], {#[], #[[3 ;; 4]]}}, {{{#[], #[]}, #[[

3]]}, #[]}, Reverse@{{{#[], #[]}, #[]}, #[]}} &;

parts = Flatten[(pattern) /@ Permutations[list, {4}], 1];

res1 = matchQ /@ parts // Quiet // Flatten When I’m playing with a calculating 24, I used some function like Inactive, My question is How can I make the output more reasonble in human writing habbit? for example, here I replace Subtract with Plus

I want to change ((6+4)+-2)*3 to ((6+4)-2)*3

StringForm is also OK, just for display