New answers tagged

3

You can try to generate all possible valid expressions and evaluate them. If the result matches your target value, print it. How can you generate all expressions? Let's start with a simplified variant of your example: The numbers 1, 2, 3, and 4 must all be used in the given order. The only allowed operators are the binary operators +, −, × and /. A division ...


1

Unfortunately, brute force is the way to go. Solving the problem with brute force will require two steps: Generate all possible expressions. Test all possible expressions. This may sound redundant to mention, but I do so for a very specific reason. You can focus your code on brute forcing the first step and then writing the generated expressions to a file ...


Top 50 recent answers are included