Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i got a maths 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=3+5 , 7+1=8 , 8-1=7 , 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? thanks a lot!

have a nice day!

share|cite|improve this question
Maybe best suited to Stack Overflow? Also just being picky, doesn't 8-1=7 and 7+=3+5 fall outside your inputs as you haven't a - or 2 +s? I like this question it got me to sign into Mathematics! – glh May 18 '13 at 9:58
each equation should have valid operator. so any equations without operator cannot be accepted. 1=1 is not accepted. – justicepenny May 18 '13 at 16:23
just post it on stack overflow.... but always stupid and negative ppl just reply with some non sense and "minus" my question, i am getting sick with those pathetic ppl in there. – justicepenny May 18 '13 at 16:35

Thinking out aloud ;)

  1. If you arranged the numbers in all possible ways noting you must have at least 2 numbers and incriminating to the maximum selected.

  2. Then reproduce each number set with the = in each valid location. This would be your starting point.

  3. Where you can then place the selected modifiers in each valid place.

    1. First one at a time.
    2. Then combining them one at a time.
  4. Then for each iteration check the formulas validity saving or rejecting as required.

This seems quite lengthy but is a place to start. I think there will be some constraints or further optimisations I've not YET thought of you can apply to decrease the number of interactions you'll need to do.

I say yet as I'll not stop thinking about this. ;)

share|cite|improve this answer
my approach is also similar like that. just like firstly pick 3 members in the array ,and these members must have an operator. then do all the combination. see if it is an equation. then pick 4 , do all combinations. and then until the length of arrays. but then i need a super computer – justicepenny May 18 '13 at 16:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.