For numbers up to 6 digits or so, I would say brute force as follows:
1) Divide your initial value into a list (array, regardless of language) of numbers. Initially, these are numbers.
2) For each pair of numbers, combine them together using one of the operators. If the result is the target number, then return success (and print all the operations performed on exit). Otherwise, if it is an integer, write down a new, smaller list consisting of the number you just counted and the number you didn't use. Or you can allow non-integer intermediate results, which will make the search space a bit larger. Binary operations:
- Add
- subtract
- multiply charged
- divide
- power
- concatenate (which can only be used for numbers that are either original digits or were created by concatenation).
3) Suppose that the square root inflates the search space to infinity, since this is a unary operator. So you will need a way to limit the number of applications, and I'm not sure what it will be (loss of accuracy, as the answer approaches 1, maybe?). This is another reason for allowing only integer intermediate values.
4) Rebirth will quickly lead to overflow. 2 ^ (9 ^ (4 ^ 8)) is too large to store all the numbers directly [although in base 2 it is pretty obvious that they ;-)]. Therefore, you will either have to accept that you can skip decisions with large intermediate values, or you will have to write a bunch of code to do arithmetic in terms of factors. Obviously, they do not interact very well with the add-on, so you may have to make some assessment. For example, just looking at the magnitude of the number of factors, we see that 2 ^ (9 ^ (4 ^ 8)) is nowhere near (2 ^ 35), so there is no need to calculate (2 ^ (9 ^ (4 ^ 8)) + 5) / (2 ^ 35). It cannot be 29485235, even if it were an integer (which, of course, is not, this is another way to exclude this specific example). I think that handling these numbers is more complicated than the rest of the problem put together, so perhaps you should limit yourself to unique authority to start with, and possibly results that correspond to a 64-bit integer, depending on what language you are use.
5) I forgot to exclude a trivial solution for any input, just by concatenating all the numbers. However, this is fairly easy to handle by simply supporting the parameter through recursion, which tells you if you have performed any operations not related to route concatenation into your current sub-problem. If you did not, then ignore the false match.
My 6-digit score is based on the fact that itโs quite easy to write a Countdown solver that runs in the second fraction, even when there is no solution. This problem is different in that the numbers must be used in order, but there are more operations (the countdown does not allow exponentiation, square root or concatenation or non-integer intermediate results). In general, I think this problem is comparable if you solve the problems with square root and overflow. If you can solve one case in a split second, then you can go too far through a million candidates in a reasonable amount of time (provided that you do not mind leaving your computer).
At 10 digits, brute force seems impossible, because you need to consider 10 billion cases, each of which requires a significant amount of recursion. Therefore, I think you will reach the limit of brute force somewhere in between.
Note also that my simple algorithm at the top still has a lot of redundancy - it does not stop you (4,7,9,1) โ (47,9,1) โ (47,91), and then later also (4.7 , 9.1) โ (4.7.91) โ (47.91). Therefore, if you do not find out where these duplicates will be duplicated, and avoid them, you will try (47.91) twice. Obviously, there is not much work when there are only 2 numbers in the list, but when there are 7 numbers in the list, you probably do not want, for example. add 4 of them together in 6 different ways, and then solve the resulting 4-point problem 6 times. Cleverness is not required here for the Countdown game, but for everyone I know about this problem, it can make the difference between coarse forcing 8 digits and coarse forcing 9 digits, which is very significant.