Results 1 to 5 of 5

Thread: need some help to solve math problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    1

    Question 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. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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. #5
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    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.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

Posting Permissions

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



Click Here to Expand Forum to Full Width