# Wolfram Language™

## Solve a Number Decomposition

The new function Groupings provides a powerful method to generate all possible results of combining certain objects and operations. In particular, it is very useful for solving some numeric games like those in the French TV program Des chiffres et des lettres, or some popular recent arithmetic questions posted in social networks.

Determine how to obtain 10 using the integers 1, 1, 5, 8 and the four basic arithmetic operations.

In:= ```ints = {1, 1, 5, 8}; ops = {Plus, Subtract, Times, Divide};```

There exist 3,840 possible combinations of those four integers and the given binary operations.

In:= `Length[combs = Groupings[Permutations[ints], ops -> 2, HoldForm]]`
Out= Here is a sample of them.

In:= `RandomSample[combs, 10]`
Out= Compute the result of each combination, many of them involving division by 0.

In:= `results = Quiet@ReleaseHold[combs];`

This is the only combination that produces 10.

In:= `Cases[Thread[Equal[combs, results]], _ == 10]`
Out= The most frequent result is 13, generated in 240 different ways.

In:= `TakeLargestBy[Tally[results], Last, 5]`
Out= 