My AP Computer Science teacher likes to play a game with his students where he writes 4 random numbers on the board and a fifth, target number. The objective is to use the four basic operations (+,−,×,÷) to get the target number. Each number can only be used once, but the operations can be reused. Order of operations does apply, and the numbers can be reordered.
Ex: Given the numbers 6 9 5 4, get to 50
Solution: (9 + 5) × 4 - 6 = 50
My teacher and I are looking for a way to find the solution(s) to a set of 5 numbers with a computer program. Because there are 24 arrangements of 4 numbers and 24 ways to arrange the 4 operations, there are 576 potential solutions to check, so brute force is not exactly easy.