problem 31, recursively