Add problem 40 solution.