Solved problem 31 recursively!