naive solution with recursion