Problem p00301 - Generation 3

Orig Description

Symmetric Ternary
It is known that if there is one weight of 1 gram, 3 grams, 9 grams, and 27 grams, you can use a balance to measure from 1 gram to 40 grams at 1 gram intervals. For example, if you place the weight you want to measure and a 3-gram weight on one side of the balance, and a 27-gram and a 1-gram weight on the other side, you know that the weight of the object you want to measure is 27-3+1=25 grams. Furthermore, if there is one weight of 1 (= 3 0) gram, 3 1 grams, ..., 3 n-1 grams, and 3 n grams, it is known that you can measure up to (3 n +1-1)/2 grams using a balance. It is also known that there is only one way to place weights so that the balance is balanced.
You can represent the way weights are placed on the balance by a string by placing the weight you want to measure and the weight on a balance, and indicating with "-" if it is on the same side as the weight of the 3 i grams, "+" if it is on the other side, and "0" if it is not placed on either side, write it in the i-th position from the right end of the string (counting the right end as 0). For example, the example of 25 grams above can be represented as "+0-+".
Now, given the weight you want to measure, create a program that outputs a string representing how to place the weights so that the balance is balanced. However, it is assumed that there is always one weight of 3 to the power of n grams for any weight.
(Note: About symmetric ternary)
The string representing the way weights are placed is called the symmetric ternary of w, which is a number represented by placing powers of 3 and writing characters representing the numbers 1, 0, and -1 for each digit. In the above string, the characters "+", "0", and "-" correspond to the numbers 1, 0, and -1, respectively. For example, the symmetric ternary of "+0-+" representing the way to weigh 25 grams represents the number 1 × 33 + 0 × 32 - 1 × 31 + 1 × 30 = 25.
Input
The input is given in the following format:
w
w (1 ≤ w ≤ 100000) is an integer representing the weight of the object to be measured.
Output
Output a string representing how to place the weights. However, the left end of the string must not be 0.
Examples
Example 1
Input:
25
Output:
+0-+
Example 2
Input:
2
Output:
+-
Example 3
Input:
5
Output:
+--

Extracted Specification

Canonicalized Input Description:

An integer \(X\) (1 ≤ \(X\) ≤ 100000), representing some quantity.

### Example Input:

```
25
```

### Function Signature:
Write a function f(X) that takes in the input. 
def f(X: int): 
    ''' 
    X: an integer
    '''

Test Case Generator

Sure! Here is a test case generator for the "Symmetric Ternary" problem statement:

```python
import random

def tcgen():
    w = random.randint(1, 100000)
    return w

# Example usage
if __name__ == "__main__":
    for _ in range(5):  # Generate 5 test cases
        print(tcgen())
```

This function generates a random integer `w` between 1 and 100000, which is the input for the problem. You can run this script to generate multiple test cases as needed.

If you want to generate test cases with the expected output for verification, you would need to implement the algorithm to convert `w` to its symmetric ternary representation. Here’s a possible implementation for that:

```python
def symmetric_ternary(w):
    if w == 0:
        return "0"
    
    result = []
    while w != 0:
        mod = w % 3
        if mod == 0:
            result.append("0")
        elif mod == 1:
            result.append("+")
            w -= 1
        else:  # mod == 2
            result.append("-")
            w = (w + 1) // 3
        w //= 3
    
    return ''.join(result[::-1])

# Example usage with output
if __name__ == "__main__":
    for _ in range(5):  # Generate 5 test cases with expected output
        w = tcgen()
        print(f"Input: {w}")
        print(f"Output: {symmetric_ternary(w)}")
        print()
```

This script first generates the random weight `w`, then computes its symmetric ternary representation using the `symmetric_ternary` function, and finally prints both the input and the output.

You can adjust the number of test cases generated by modifying the range in the loop.

Extract Arguments

def extract_arguments(fh):
    w = int(fh.readline().strip())
    return w