This is based on a game one of my math teachers used to play in middle school. He would write 5 random one-digit numbers on the board, and then a random two-digit number. We would try to create an equation that used all 5 of the one-digit numbers to yield the two-digit number. Here are some examples with solutions to explain this better:
Input: Solution:
7 5 4 8 4 34 5*8-7+4/4 = 34
3 1 5 7 6 54 (7+3)*6-5-1 = 54
3 9 2 1 6 87 9*(2+1)*3+6 = 87
2 1 6 9 7 16 (9-7+6*1)*2 = 16
2 4 5 8 6 96 8*(5+6)+2*4 = 96
3 8 4 5 4 49 8*(4+4)-3*5 = 49
This challenge is to write a program that can generate such equations for a given input. The input can be provided either via the command line or via a prompt. The 5 one-digit numbers will always be entered first (in no particular order), followed by the two-digit number. The program will then print out a solution equation it finds; you do not have to handle situations where there is no solution. The function must be capable of using the following operations in the equation: addition, subtraction, multiplication, and division. If you would like to allow additional basic operations, that's fine as long as they remain in the spirit of the challenge (negation, exponentiation, and modulus would be nice additions). Order of operations follows the standard math rules, so parenthesis will be needed for grouping. The program must take less than a minute to run on a modern computer.
Programs will be scored based on code length (including required whitespace). Note: division must be exact, not rounded or truncated to nearest integer.