Python 2: 59 chars --------------- <!-- language: lang-python --> n=input() s="" while n:s="0+-"[n%3]+s;n=-~n/3 print s or'0' Generates the balanced ternary digit-by-digit from the end. The last digit is given by the residue `n%3` being `-1`,`0`, or `+1`. We then remove the last digit and divide by 3 using Python's floor-divide `n=(n+1)/3`. Then, we proceed recursively with the new last digit until the number is 0. A special case is needed for the input `0` to give `0` rather than the empty string. --- The specs don't allow this, but if one could write a function instead of a program and output the empty string for 0, a 40 char solution would be possible. <!-- language: lang-python --> g=lambda n:n and g(-~n/3)+"0+-"[n%3]or""