A function $f$, defined on the set of positive integers, has $f(1) = 2$ and $f(2) = 3$.
Also $f(f(f(n))) = n + 2$ if $n$ is even and $f(f(f(n))) = n + 4$ if $n$ is odd.
What is $f(777)$?
I'm not sure where to start. I've tried looking for a pattern by finding that $f(3) = 5, f(4) = 7, f(5) = 4, f(6) = 11, f(7) = 9, f(9) = 6,$ etc. This doesn't seem to lead anywhere. I was also wondering about how if I find the value of $n$ for $f(777) = f(f(f(n)))$ that could give me the answer. Still unclear how I will find this though.
You’ve seen how to calculate the first few values of $f$ after the two that you were given, e.g.,
$$f(3)=f(f(2))=f(f(f(1)))=1+4=5\;,$$
$$f(5)=f(f(3))=f(f(f(2)))=2+2=4\;,$$
and
$$f(4)=f(f(5))=f(f(f(3)))=3+4=7\;.$$
If you list the first few values in the order in which they were obtained, you get
$$\color{red}2,3,5,\color{red}4,7,9,\color{red}6,11,13,\color{red}8,15,17,\color{red}{10}\;.$$
This does show a pattern, which I’ve tried to emphasize by giving the even and odd numbers different colors. You may also notice that this sequence of numbers obeys a rather simple recurrence: if we call the $n$-th number $a_n$, we have
$$a_n=\begin{cases} a_{n-3}+4,&\text{if }a_{n-3}\text{ is odd}\\ a_{n-3}+2,&\text{if }a_{n-3}\text{ is even.} \end{cases}$$
It’s possible to use this information to determine $n$ such that $a_n=777$, and from that with a bit of work you can get $a_{n+1}=f(a_n)$.