I was attending a coding competition and this question came up
There is a box containing n chocolates. You can either take 1 chocolate or 3 chocolates at a time until its empty. So in total how many ways you can empty the chocolate for a given n.
Eg: n = 3
ways you can take out is 2 ie:
111
3
ways you can take out when n=4 is 3 ie:
1111
31
13
likewise, I have calculated manually for n=5 -> 4 etc etc..
so the result sequence comes up like 2,3,4,6,9...
I am not able to figure out what kind of relation it has or how do I solve it. I'm not able to figure out what kind of problem it is as well (Permutation, combinations, series?). let me know if I need to post any more details.
I think this problem is one of the problems related to recurrence relation.
Let $a_n$ be the number of ways.
For example, $a_1 =1$, $a_2 = 1$, $a_3=2$, $a_4=3$ as you mentioned above.
Let's think of the number of ways for $n$. Obviously, it is $a_n$.
If we take 1 chocolate at the first time, then the number of remaining chocolates is $n-1$.
And the number of ways for $n-1$ is $a_{n-1}$.
If we take 3 chocolate at the first time, then the number of remaining chocolates is $n-3$.
And the number of ways for $n-3$ is $a_{n-3}$.
Therefore, for $n \geq 4$,
$$a_n = a_{n-1} + a_{n-3}.$$
The initial value is given as above.