need some help to solve math problem-VBForums

Thread: need some help to solve math problem

1. need some help to solve math problem

can anyone pls guide me to solve the math problem.
there is an array of numbers and operators and one solution no say 34
e.g.
input 1: {1, 2, 4, 6, 9, 18, 24, 25, 28, 40, +, -, *, /, ^ }
input 2: 34
need to find all the possible eqns which result is 34.
e.g. a)6 * 9 - 20
b)40 - 6

any idea or algorithm for the same.

2. Re: need some help to solve math problem

The only route would be to calculate every possible combination of numbers and operators. This why they set problems like this for humans and not computers!

If you really want to do it then you'll need to loop through every combination of

value/operator/value
value/operator/value/operator/value
value/operator/value/operator/value/operator/value

etc. etc.

3. Re: need some help to solve math problem

Welcome to the forums jessica1

Could you please confirm whether you want to do this in VB.Net or or something else?

4. Re: need some help to solve math problem

Hello jessica1,

For now, I am going to move this thread to the Maths Forum, as it would appear that your initial question is regarding how to perform the mathematical problem at hand.

Gary

5. Re: need some help to solve math problem

I'm sorry jessica, but I don't really believe your problem description--it makes the problem completely intractible. You didn't put any constraints on the formulas, and in that case considering only the length 10 formulas there are 4862 parenthesizations to consider, 5^9 operator choices per parenthesization, and 10^10 term choices, resulting in a ridiculous ~100 billion billion formulas to check. Some of these are certainly redundant, eg. since addition and multiplication are commutative, but not a large enough fraction to make this tractable.

Even assuming each number and operator can be used only once the problem remains remarkably difficult, with (counting similarly to the above) 2551724110 formulas to check. In that case there are around 1.5 million formulas to check only going up to 4 terms. You have to have a lot of infrastructure to solve the problem by brute force--various methods of higher order iteration, arbitrary precision integer and rational number arithmetic, a way to algebraically handle fractional exponents, .... The ^ and / operators really complicate the search. I wrote some code that on this machine is able to do around 10000 formulas per second, which will still take 3 days of CPU time to finish. I won't let it finish--unfortunately it does not handle fractional exponents nor extremely large intermediate results, both of which will cause it to miss a small fraction of valid formulas. In the first 10 million formulas, it found 4516 of them that work, eg.

(6+(28*((25-24)^9)))
(40-(6/(1^(4+28))))
(25+(9/((1-2)^28)))
(9+(25*(1^(2/40))))
(((28*1)+24)-18)
(2*(24-((1^4)+6)))
(28+(9*(24/(40-4))))
(18+(24-(4^(9/6))))
(((40-24)^1)+18)
(18+(2^(28-24)))
((40+28)*(1/2))
(40+(2*((6^1)-9)))
(18+(28-((6^1)*2)))
(6+(40-((24*1)/2)))

I find it very hard to believe that you'd be assigned a problem as difficult as the one you've described, or even the simpler version I've discussed, without apparently having any idea how to solve it yourself. Certainly you have not communicated it correctly.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•