Comments

beautiful, thanks for sharing :)

Let's assume we have a ternary representation of 200 (it's decimal equivalent is 2*(3^2)+0*(3^1)+0*(3^0)=18) now if we replace 2 with 1 and replace all 0s to the right of 2 with 1 then we get 111 which is ternary representation of 13. So you see we get a number which is less than 18 but we want a number greater than 18 so we have to set one more bit to 1 to the left of 2 which makes out ternary representation to 1111 (it is decimal equivalent of 40) but now if we make all 1 to 0 except the leftmost 1 then we get 1000 (it's decimal equivalent is 27 ) which is the least number we can get which is a good number and greater than 18. Hope this example will help you to understand the solution better.