Well done
So 2 measurements for 9 balls...if anyone can beat that I'll be impressed
I guess strictly speaking, it's only log_3 x if x is a power of 3. Otherwise, it's the ceiling of log_3 x (that is, the smallest integer greater than log_3 x. This accounts for that fact that with 10 balls for example, it could take 3 measurements if the gold ball is in the final pile of four.
How convenient that the original problem used a power of 3, eh?
--Tim