#P1236. 24 Game: Achieve 24 Using Four Numbers
24 Game: Achieve 24 Using Four Numbers
24 Game: Achieve 24 Using Four Numbers
This is a classic number game that has been popular for decades. Given four natural numbers between 1 and 9 (inclusive), your task is to perform arithmetic operations to obtain the value \(24\). You are allowed to use the following operations: \(+\), \(-\), \(\times\), and \(\div\), and you may also use parentheses \( ( \) and \( ) \) to change the order of operations.
Important: All intermediate results in your calculation must be integers. For example, the operation \((2 \times 2) \div 4\) is valid since it yields an integer, but \(2 \times (2 \div 4)\) is not allowed because \(2 \div 4\) is not an integer division.
Example: For the input numbers 1, 2, 3, and 7, one valid expression is:
1 + 2 + 3 \(\times\) 7 = 24
inputFormat
The input consists of a single line containing four space-separated integers. Each integer is between 1 and 9 (inclusive).
outputFormat
Output a single line containing either True
if it is possible to form an expression that equals 24 using the given numbers and operations under the specified rules, or False
if no such expression exists.
sample
1 2 3 7
True