I need help creating an algorithm. I am currently developing something for a class that I accept.
Given 4 numbers, I need to find the entire (or at least the first) combination of 4 numbers, using the basic operations (+ - * /) to make a specific answer.
For example, if the numbers [1,2,3,4] are given. and I have to answer 12. I see (without a program) that (2-1) * 3 * 4 = 12
But for more complex numbers, it can be harder to solve just thinking about it. Therefore, I need a program that will help me find at least one possible combination to solve the problem .
Please note that in the 4 numbers indicated, numbers can be repeated, but each number can be used only once. For example, a set of 4 may be [2,3,3,4]. But in this set, 2 and 4 cannot be used more than once.
Initially, I had a power-search plan to find all possible combinations / orders from every four numbers, and then repeat all the operations. Later I realized that this would not work, since it does not take into account operations like (1-2) * (3 + 4).
So I was wondering if anyone has an idea on how I can solve this problem?
Please keep in mind that I'm still fairly new to programming, so I don’t understand some of the more complex terms and functions. But I can do nice things like loops and arrays.