This problem concerns the so-called balanced ternary system for representing numbers. It is a Base 3 system in which the digits can be 1, 0, or -1.
In balanced ternary, the number 8 would be represented as 9 (or 3^2) minus 1 (or 3^0). Typographically we will use "|" for one, "o" for zero (that's a lower-case O), and "-" for negative one. So if the decimal input d is the number 8, the balanced ternary output is the string "|o-". Thus
dec 8 => bt "|o-"
Here are some more examples.
dec 3 => bt "|o" dec 15 => bt "|--o" dec 52 => bt "|-o-|"
Given an integer d, return the string bt. Leading zeros should always be suppressed.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers73
Suggested Problems
-
Extract leading non-zero digit
2244 Solvers
-
Increment a number, given its digits
683 Solvers
-
middleAsColumn: Return all but first and last element as a column vector
647 Solvers
-
Set the array elements whose value is 13 to 0
1438 Solvers
-
Calculate Amount of Cake Frosting
28982 Solvers
More from this Author54
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I have a 16 point hack solution, but https://www.mathworks.com/matlabcentral/cody/players/1379371's solution is too good. For those who need a clue, sum(3.^(0:9))=29524 Just increase that 9, and you're good until overflow or roundoff get you.