#P1834. 24 Game Challenge
24 Game Challenge
24 Game Challenge
Given 4 integers (each from 1 to 9), determine an expression by inserting the operators \(+,\ - ,\times, \div\) and appropriate parentheses such that the expression evaluates exactly to \(24\). All intermediate results during the computation must be integers. For instance, the expression \((2 \times 2)/4\) is allowed (since \(4/4 = 1\) is an integer), but \(2 \times (2/4)\) is not allowed because \(2/4\) is not an integer.
If a valid expression exists, output any one valid expression (the output expression should include parentheses to indicate the order of operations). If no valid expression exists, output the string NONE.
This problem is known as the 24 Game challenge. Good luck cheating at 24!
inputFormat
The input consists of 4 space-separated integers, each in the range from 1 to 9.
outputFormat
If there exists an expression using the 4 numbers and the operations +, -, *, / (with integer intermediate results) that evaluates to 24, output any one such expression. Otherwise, output "NONE".
sample
4 7 8 8
(7-(8/8))*4