A function $g$ defined for all positive integers $n$ satisfies $g(1) = 1$; for all $n\ge 1$, either $g(n+1)=g(n)+1$ or $g(n+1)=g(n)-1$; for all $n\ge 1$, $g(3n) = g(n)$; and $g(k)=2001$ for some positive integer $k$. Find, with proof, the smallest possible value of $k$.
Problem
Source: XII Cono Sur Mathematical Olympiad (2001)
Tags: function, induction, algebra unsolved, algebra