Solution for recursion assignment