Problem 21: complete solution.