Q:

how to generate all possible equations with a set of number and operators?

I got a maths and programming problem.
For given that a set of character {1,2,3,4,5,6,7,8,9,+,-,*,/}. And then by using the set of characters to randomly generate 10 (or let say N) characters in an array, i.e. [1,+,1,∗,3,5,7,8,1]. After that I need to find all the possibility of equations by using this array of characters plus 1 character '='.
Therefore in this case, [1,+,1,∗,3,5,7,8,1] it would be like the following equations: 1*1=1 , 3+5=8 ,  7+1=8 ,  15=8+7 , 15+3=18 (maybe more)
It can form multiple digit operation, i.e 15+3=18
so my question is I am trying using a program to generate the equations all. Could you guys give me some ideas what kind of algorithms can do so? or any methods do it?
my current approach:
my approach is not fast enough. so the idea is, the minimum equation needs 3 number and 1 operator. and

i start from randomly pick 4 members from the generated array. if these 4 members have one operator, 
then i would add the '=' 
form all the possible orders . e.g. 1,1,2,+ , i will have 112+=, 121+= ,1=12+ .... loop through all that. and 
then increase to 5 members and loop through it... 
do it until the length of array generated

A:

As already mentioned in the comments, this appears to be NP-complete, thus exponential, thus it will take really long, but here's what I'd do nonetheless:
For each possible subset A of the input do the following:
Generate all permutations of A.
So each permutation corresponds to an equation (or that thing that's like an equation but doesn't have an = sign).
Now note that there's going to be a lot of invalid 'equation's. Things like 1**1. You need to ignore all of these as you go. Roughly anything starting or ending with an operator or with 2 operators in a row is invalid (or maybe not, 1*-2, -2+1 and 1--1 (?) is valid (what about 1++1 and +1+2?), but anyway, I'm sure you can figure something out).
For each valid permutation, add the number resulting from evaluating it to a set (well, a (multi-)map of number to equation).
Do the same for all permutations of remaining items when A has been removed from the input (resulting in another generated set).
Now all numbers that appear in both sets are valid equations. Note that (for a lack of desire to explain) you'll do a CROSS JOIN-like process on all equations that have the same number.
Did we just generate each set twice, once on the left, once on the right? Whoops. Ok, here's a fix: "Pick any element, for each possible subset A of the input containing that element...".
Something to think about - separating out the operators
Advantage: It may be a lot faster (not really sure, it may even be slower)
Disadvantage: It's a lot more complex
Pre-process the input, removing all operators and simply have a count for each operator.
Do exactly the same as above, but, for each permutation, also generate all permutations of where the operators can go. If done right, you should be able to completely avoid invalid equations.
And also have multiple sets to put the numbers into (so you'll have 2 sets of sets), one for each possible amount of each type of operators allowed, which you'll then compare against another set (in the other set of sets) such that the number of operators are all used.
To explain with an example:
Input: [1,*,1,3,5,7,8,+,+,1]
Input without operators: [1,1,3,5,7,8,1]
Operators:
Operator  Count
+         2
*         1

An example subset: [1,7,8,1]
Its complement: [1,3,5]
Now we'll have 2x 6 sets, one for each combination of possible operators for both sets:
            ++*      ++      +*      +      *      NONE
Subset      +1*1+78  11+7+8  1*1+78  117+8  1*178  1178
Complement  +3*5+1   3+5+1   3*5+1   35+1   3*51   351

The above are just examples, there are obviously a lot more than 1 equation going into each set, you need to consider everywhere the operators can go, for example, considering ++*:
+1+1*78
+1+17*8
+11+7*8
1+1+7*8
1*1+7+8
1+1*7+8
etc.

And I just considered the permutation 1178 of the example and 351 of the complement, but all permutations will need to be added (i.e. 1187, 1718, 1781, ... and 315, 513, 531, ...).
Once all of these are added to the sets, you match up the sets as follows, so we use all the operators in an equation:
Subset      Complement
++*    with NONE
++     with *
+*     with +
+      with +*
*      with ++
NONE   with ++*

To give some better idea of what happens, and assuming we're really bad at maths, we can say: (taken from the above grid)
+1*1+78 = 351
11+7+8 = 3*51
1*1+78 = 35+1
etc.

Now you'll match the equations up using the value it evaluates to (using sorted sets will allow you to step through both at the same time in linear time). So, let's say equation A and B of the subset both evaluate to 79, and equation C and D of the complement also evaluate to 79. Now you'll match them up as follows: (this is what I meant by CROSS JOIN)
A = C
A = D
B = C
B = D

and also (if you want these):
C = A
C = B
D = A
D = B

I hope that clarifies it.

