Myth Busters
Time limit1sMemory limit128 MB
For each city's list of four-digit carriage IDs, decide whether every ID can reach the value 10 by permuting its digits and inserting +, -, *, / with parentheses.
- Level
Medium7 of 10
- Topics
- Brute force, Recursion, Math, Implementation
- Solved
- No attempts yet
Problem
Every train carriage operated by CityRail of Sydney has a unique four-digit ID number. A common myth among local school pupils is that any ID number can be turned into the number by permuting its four digits, adding brackets, and combining them with the arithmetic operations in the set {+, -, *, /}.
Your task is to verify whether this myth actually holds, both for the carriages of CityRail of Sydney and for train carriages from other cities whose ID numbers were collected.
Note: here / denotes integer division. Most of you already know this, but as two examples, 5 / 2 is 2 and 2 / 5 is 0.
Input
The input consists of several test cases. Each test case is given as follows:
- A line with a single integer (), the number of IDs collected from one city.
- lines follow, each containing one four-digit number.
A line containing only 0 marks the end of the input and must not be processed.
Output
For each test case, print the conclusion of your investigation on its own line as TRUE or BUSTED. Print TRUE if the myth holds for every carriage ID number of that city (that is, every one of them can be turned into ); otherwise print BUSTED.