trivial solution.
a recursive way to solve the problem.